我有一個將選定日期作爲字符串傳遞給方法的日曆。在此方法中,我希望生成從所選開始日期開始到選定結束日期的所有日期的列表,顯然包括所有日期之間的所有日期,無論所選開始日期和結束日期之間有多少天。如何在兩個日期之間循環
下面我有方法的開始,它接受日期字符串並將它們轉換爲DateTime變量,以便我可以使用DateTime計算函數。但是,我似乎無法計算出如何計算開始和結束日期之間的所有日期? 很明顯,第一階段是從結束日期中減去開始日期,但我無法計算其餘的步驟。
幫助大大加分,
親切的問候。
public void DTCalculations()
{
List<string> calculatedDates = new List<string>();
string startDate = "2009-07-27";
string endDate = "2009-07-29";
//Convert to DateTime variables
DateTime start = DateTime.Parse(startDate);
DateTime end = DateTime.Parse(endDate);
//Calculate difference between start and end date.
TimeSpan difference = end.Subtract(start);
//Generate list of dates beginning at start date and ending at end date.
//ToDo:
}
在生成的值(日期,小時,分鐘)之間制定了一個步驟 – 2009-07-29 09:51:01