如何找到两个日期时间对象之间的时间差? [英] How do I find the time difference between two datetime objects?
本文介绍了如何找到两个日期时间对象之间的时间差?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何找到ASP.NET两个日期时间对象之间的时间差?
How do I find the time difference between two datetime objects in ASP.NET?
推荐答案
下面的例子演示了如何做到这一点:
The following example demonstrates how to do this:
DateTime a = new DateTime(2010, 05, 12, 13, 15, 00);
DateTime b = new DateTime(2010, 05, 12, 13, 45, 00);
Console.WriteLine(b.Subtract(a).TotalMinutes);
当因为有/次日期之间30分钟的差别执行该打印出30。
When executed this prints "30" since there is a 30 minute difference between the date/times.
DateTime.Subtract(DateTime的X)的结果
是的 TimeSpan对象这给其他有用的属性。
The result of DateTime.Subtract(DateTime x)
is a TimeSpan Object which gives other useful properties.
这篇关于如何找到两个日期时间对象之间的时间差?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文