如何使用datetime
中的for
循环?如何在for循环中使用datetime?
有两个变量duedate
和returndate
,返回日期是当前日期和duedate增加一天,等于返回。
我该如何在for循环中使用它?
如何使用datetime
中的for
循环?如何在for循环中使用datetime?
有两个变量duedate
和returndate
,返回日期是当前日期和duedate增加一天,等于返回。
我该如何在for循环中使用它?
你可以使用:
DateTime start = ...;
DateTime finish = ...;
for (DateTime x = start; x <= finish; x = x.AddDays(1))
{
... // use x
}
for(DateTime date=duedate;date.Date<DateTime.Now.Date;date=date.AddDays(1))
{
}
像这样
这应该让你开始:
DateTime end = new DateTime();
for (DateTime start = new DateTime(); start < end; start.AddDays(1))
{
//process
}
的另一种方式:
DateTime start = new DateTime();
DateTime endval = new DateTime();
//It means it is 1 hour interval:
TimeSpan inctrementval = new TimeSpan(1, 0, 0);
for (DateTime t = start; t < endval; t += incrementval)
{
//Your code will not reach endval
}
或者:
for (DateTime t = start; t <= endval; t += incrementval)
{
//Your code will reach endval
}