我如何每两个月做一份工作?

编程入门 行业动态 更新时间:2024-10-27 11:17:42
本文介绍了我如何每两个月做一份工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我必须根据日期过滤今天要运行的作业。因此,对于每个计划的日期,我将它与DateTime.Today.Date进行比较,并获取计划在今天运行的作业列表。 如何根据给定的周期时间过滤周期性作业? 示例: - >如果周期时间为0,则在预定日期每月运行。 - >如果周期时间为2,第一次在预定的一天运行工作,然后每两个月运行一次。 我尝试过的事情: 我必须以这种方式添加周期时间,如果计划日期= 3/7/2016,周期时间= 2,如果计划日期==今天,则运行服务并添加2个月(2016年5月7日)并在该日期运行服务并添加2个月(2016年7月7日)等等。 我这样写,但如果它曾经返回true它没有检查其他条件。这对我的情况不起作用。 var x =预定日期; if(cycleTime == 0&& x ==今天) { 返回true; } if(cycleTime!= 0&& ; x ==今天) { x = x.AddMonths(cycleTime); if(x ==今天) { 返回true; } }

I have to filter the jobs to be run today based on the date. So, for every scheduled date, I am comparing it to DateTime.Today.Date and getting a list of jobs that are scheduled to run today. How can I filter the recurring job based on the given cycle time? Example: ->If cycle time is 0, run every month on the scheduled date. ->If cycle time is 2, for the first time run the job on scheduled day and then run every two months. What I have tried: I have to add cycle time in this way, if schedule date = 3/7/2016, cycle time =2, and if scheduled date == today, run service and add 2 months(5/7/2016) and run service on that date and add 2 months(7/7/2016) and so on. I wrote this way, but if it once returns true it is not checking the other condition. And this is not working for my scenario. var x = Scheduled date; if (cycleTime == 0 && x == today) { return true; } if (cycleTime != 0 && x== today) { x = x.AddMonths(cycleTime); if (x== today) { return true; } }

推荐答案

if (cycleTime != 0 && x== today) { x = x.AddMonths(cycleTime); if (x== today) // x no longer equals today { return true; } }

您已将x的值更改为比今天大几个月,所以在第二次测试时它不会等于。为什么你甚至需要第二次测试?

You have changed the value of x to be some number of months greater than today, so on the second test it will not be equal. Why do you even need the second test?

更多推荐

我如何每两个月做一份工作?

本文发布于:2023-11-17 03:35:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1608679.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:两个月   工作

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!