如何减去从另一个日期时间日期时间? [英] How to subtract a datetime from another datetime?
问题描述
我如何提取两个日期时间值从另一个日期时间价值,有结果保存到一个双?
How do I subtract two DateTime values from another DateTime value and have the result saved to a double?
推荐答案
在.NET中,如果你从另一个减去一个的DateTime
的对象,你会得到一个时间跨度
对象。然后,您可以使用该蜱
属性时间跨度
对象拿到两<$ C $的蜱数量C>日期时间的对象。由龙
,不是双击
。
In .NET, if you subtract one DateTime
object from another, you will get a TimeSpan
object. You can then use the Ticks
property on that TimeSpan
object to get the number of ticks between the two DateTime
objects. However, the ticks will be represented by a Long
, not a Double
.
DateTime date1;
DateTime date2;
Long diffTicks = (date2 - date1).Ticks;
有在时间跨度
对象上的其他有趣的属性,如 TotalMilliseconds
和 TotalMinutes
和类似的东西,可以帮助你,而且可能会更你要找的是什么
There are other interesting properties on the TimeSpan
object like TotalMilliseconds
and TotalMinutes
and things like that which can help you out, and may be more what you are looking for.
这篇关于如何减去从另一个日期时间日期时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!