8

我想知道两个日期之间有多少分钟?

示例:现在 - 明天在确切时间将返回 1440。

4

3 回答 3

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

int diff = dt2.Subtract(dt1).TotalMinutes;
于 2008-10-16T23:20:57.327 回答
7

查看 TimeSpan 类。

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

        TimeSpan diff = date2.Subtract(date1);
        Console.WriteLine(diff.Minutes);
于 2008-10-16T23:19:13.413 回答
-2
DateTime currentTime = DateTime.Now;
DateTime tommorowTime = currentTime.AddDays(1);
TimeSpan diffTime = tommorowTime - currentTime ;
Console.WriteLine(diffTime.TotalMinutes);
于 2008-10-16T23:19:30.013 回答