如何减去从另一个日期时间日期时间? [英] How to subtract a datetime from another datetime?

查看:404
本文介绍了如何减去从另一个日期时间日期时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何提取两个日期时间值从另一个日期时间价值,有结果保存到一个双?

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆