如何使用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
}