开发者

Get DateTime Difference in a Array

开发者 https://www.devze.com 2023-03-09 17:33 出处:网络
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

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();   
0

精彩评论

暂无评论...
验证码 换一张
取 消