2 DateTime之间的确切时间?

时间:2008-10-16 23:17:37

标签: c# .net datetime .net-2.0

我想知道2个日期之间有很多分钟?

示例:现在 - 确切时间的tommorow将返回1440。

3 个答案:

答案 0 :(得分:11)

DateTime dt1 = DateTime.Now;
DateTime dt2 = DateTime.Now.AddDays(1);

int diff = dt2.Subtract(dt1).TotalMinutes;

答案 1 :(得分:6)

查看TimeSpan类。

        DateTime date1 = DateTime.Now;
        DateTime date2 = DateTime.Now.AddDays(1);

        TimeSpan diff = date2.Subtract(date1);
        Console.WriteLine(diff.Minutes);

答案 2 :(得分:-2)

DateTime currentTime = DateTime.Now;
DateTime tommorowTime = currentTime.AddDays(1);
TimeSpan diffTime = tommorowTime - currentTime ;
Console.WriteLine(diffTime.TotalMinutes);