两个DateTimes之间的区别C#? [英] Difference between two DateTimes C#?
本文介绍了两个DateTimes之间的区别C#?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要一个可以将下面两个日期之间的差异返回为24的函数。
I need a function that can return the difference between the below two dates as 24.
DateTime a = new DateTime(2008, 01, 02, 06, 30, 00);
DateTime b = new DateTime(2008, 01, 03, 06, 30, 00);
推荐答案
您可以执行以下操作:
TimeSpan duration = b - a;
在timespan类中有很多内置方法来做你所需要的,例如
There's plenty of built in methods in the timespan class to do what you need, i.e.
duration.TotalSeconds
duration.TotalMinutes
可以找到更多信息 here 。
这篇关于两个DateTimes之间的区别C#?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文