I need to Predict the date time differnce in a array of cells...
ex:
From Date:04/30/2011 To Date:05/30/201开发者_如何学编程1
the array cell contains the dates from 04/30/2011 to 05/30/2011
You can use the CalendarPeriodCollector of this library:
// ----------------------------------------------------------------------
public void CalendarPeriodCollectorSample()
{
CalendarPeriodCollector collector =
new CalendarPeriodCollector( new CalendarPeriodCollectorFilter(),
new TimeRange( new DateTime( 2011, 4, 30 ), new DateTime( 2011, 5, 30 ) ) );
collector.CollectDays();
foreach ( ITimePeriod period in collector.Periods )
{
Console.WriteLine( "Period: " + period ); // all days between 04/30/2011 and 05/30/2011
}
} // CalendarPeriodCollectorSample
You can also specify exclusion days (holidays), or collect the periods by hours.
I think you are looking for this:
DateTime start = Convert.ToDateTime("04/30/2011");
DateTime end = Convert.ToDateTime("05/30/2011");
List<DateTime> dateArray = new List<DateTime>();
while (end > start.AddDays(1))
{
end= end.AddDays(-1);
dateArray.Add(end);
}
DateTime[] array = dateArray.ToArray();
精彩评论