如何计算csharp中的总时间 [英] how to caluclate total time in csharp
本文介绍了如何计算csharp中的总时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有开始时间和结束时间,我想计算总时间.
开始时间7.00AM
总时间10.00AM
结束时间我想要答案3
请帮助我
i have start time and end time and i want to calculate total time.
start time 7.00AM
Total time 10.00AM
End time i want the answer 3
please help me
推荐答案
这很简单.总时间始终为EndTime-StartTime.
如果您从另一个日期中减去一个日期时间值,则结果将是一个TimeSpan对象,其名称为总时间".
This is simple math. Total time is always EndTime - StartTime.
If you subtrace one datetime value from another then result is a TimeSpan object with the "total time" as you call it.
假定开始时间和结束时间均为DateTime
类型:
Assuming the starttime and end times are both of typeDateTime
:
TimeSpan span = endTime - StartTime;
此时,您可以使用TimeSpan
对象中的属性来确定时间.
At this point, you can use the properties in the TimeSpan
object to determine the amount of time.
尝试:
Try:
DateTime start = new DateTime(1, 1, 1, 7, 0, 0);
DateTime end = new DateTime(1, 1, 1, 10, 0, 0);
TimeSpan ts = end - start;
int diffHours = ts.Hours;
这篇关于如何计算csharp中的总时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文