如何减去DateTime值和获取时间 [英] How to subtract DateTime values and get the Time

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

问题描述

我的基本意思和具体情况是。

What I basically mean and the exact scenario is.

您在ASP.NET页2 TimeEdit控制。那些采取DateTime值。 现在首重presents你开始工作,当你完成工作的第二个时间。 可以采取工时一种有效的方法?

You have 2 TimeEdit controls in an ASP.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?

例如。 2011年10月6日09:00 - 2011年10月6日17:00 - > 08:00的工作时间...

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

推荐答案

减去两个的DateTime s给出你一个时间跨度目标:

Subtracting two DateTimes gives you a TimeSpan object:

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

这篇关于如何减去DateTime值和获取时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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