查找基于每周,每月计划的下一个日期时间日期、时间、计划

2023-09-06 15:08:12 作者:半夏花开

我想基于按月或每周计划找下一个预定日期。

I am trying to find the next scheduled date based on either a monthly or a weekly schedule.

例如。

ScheduleMode: M or W for monthly or weekly
Monthly:
    1|15|29 will run on the 1st, 15th and 29th of every month

Weekly:
    1|3|5 will run every Monday, Wednesday and Friday

我怎么去搞清楚什么下一个日期时间将根据这些数据?

how do I go about figuring out what the next Datetime will be based on this data?

例如。 2013年12月16日运行一周1 | 3 | 5,接下来的日程安排将二〇一三年十二月一十八日

e.g. 12/16/2013 running weekly 1|3|5, next schedule will be 12/18/2013

推荐答案

您可以尝试使用枚举 System.DayOfWeek 。出现这种情况是从 DateTime.DayOfWeek 的返回类型,你可以用它来找到你的起始日期是星期几。

You might try to use the Enum System.DayOfWeek. That happens to be the return type from DateTime.DayOfWeek, which you can use to find the weekday of the your starting date.

这是,你应该能够找到使用 DateTime.AddDays(X) DateTime.AddMonths第二天(S)(X )(用一些简单的加减寻找时考虑当前工作日或日期到 X )。

From that, you should be able to find the next day(s) using DateTime.AddDays(x) or DateTime.AddMonths(X) (with some simple addition and subtraction to take the current weekday or date into account when finding x).

提示:如果您有解决这个问题,一定要准确地了解你的需要的第一位。如果需要的话,写下简单的英语你的需求,然后再尝试$ C C是$。一旦你的定义的问题的清楚,解决它实际上应该不会太难...

Tip: If you have problems solving this, make sure you understand exactly what you need first. If necessary, write down your requirements in plain English before you try to code it. Once you've defined the problem clearly, solving it should actually not be too hard...