开发者

How to subtract DateTime values and get the Time

开发者 https://www.devze.com 2023-03-12 03:41 出处:网络
What I basically mean and the exact scenario is. You have 2 TimeEdit controls in an A开发者_JAVA技巧SP.NET page. Those take DateTime values.

What I basically mean and the exact scenario is.

You have 2 TimeEdit controls in an A开发者_JAVA技巧SP.NET page. Those take DateTime values. Now the first represents the time you start working and the second when you finished working. Can take the working hours with an efficient way?

e.g. 10/6/2011 09:00 - 10/6/2011 17:00 --> 08:00 working hours...


Subtracting two DateTimes gives you a TimeSpan object:

TimeSpan span = timeEnd - timeStart;
Console.WriteLine("Total work hours: {0}", span.TotalHours);


Simply subtract them:

var workingTime = dateTimeEnd - dateTimeStart;
0

精彩评论

暂无评论...
验证码 换一张
取 消