有没有办法编写一个公式,将n天数添加到返回新日期的现有日期,不包括周末?
问问题
690 次
1 回答
0
您的意思是“给定一天,添加任意天数,但确保新日期不属于周末?”
如果是这样,您选择的语言应该很容易为您提供确定日期是星期几的功能。通常,0 是星期日,6 是星期六。
这是一些伪代码:
newDate = myDate + random(1, n); // n is whatever largest integer you want.
//random(1, n) would be give me any number between 1 and n inclusive.
while ((newDate.dayOfWeek == 0) || (newDate.dayOfWeek == 6))
newDate = myDate + random(1, n);
// keep on generating a new date until it's not Sunday or Saturday.
// At this point, newDate is guaranteed not to fall on a weekend.
于 2013-08-31T01:57:05.090 回答