Fork me on GitHub

C# 获取时间区间内所有的时间以及天数

var startTime = DateTime.Parse("2023-6-25");
var endTime = DateTime.Parse("2023-6-29");
int validDay = 0;

for (DateTime currentDate = startTime; currentDate <= endTime; currentDate = currentDate.AddDays(1))
{
    Console.WriteLine(currentDate);
    validDay++;
}

Console.WriteLine(validDay);
Console.ReadKey();

 

posted @ 2023-06-26 15:07  WantRemake  阅读(215)  评论(0编辑  收藏  举报