他工作了几个小时? [英] he has worked how many hours ?

查看:90
本文介绍了他工作了几个小时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我使用c#在asp.net上工作,我希望创建一个与出勤和加班相关的小模块。

意味着,一个人带着那个日期时间进入并且还带着该日期时间离开,



如输入日期:15/12/2014 21:00

请假日期:2014年12月16日11:00



所以,我想知道,他已经工作了多少小时?,以及日期时间。

通过手动他已经工作了大约14个小时。但我想用C#计算。







谢谢和问候。

Hello,

I have working on asp.net with c#, In I want to create one small module which related attendance and overtime.
Means, One man enter with that datetime and also leave with that datetime,

like Enter Date: 15/12/2014 21:00
Leave Date: 16/12/2014 11:00

so, I want to know, he has worked how many hours ?, with above datetime.
By manually he has worked around 14 Hours. but i want calculate with C#.



Thanks & Regards.

推荐答案

使用 TimeSpan [ ^ ]。


类似于:

Something like:
string enter = "15/12/2014 21:00";
string leave = "16/12/2014 11:00";
DateTime dtEnter = DateTime.Parse(enter);
DateTime dtLeave = DateTime.Parse(leave);
TimeSpan tsWorkHours = dtLeave - dtEnter;
Console.WriteLine("Work hours {0}", tsWorkHours.Hours);


你必须使用DateTime.Subtract()方法。

然后你必须获得TimeSpan的TotalHours属性。



You must use DateTime.Subtract() method.
Then you must get the TotalHours property of the TimeSpan.

DateTime enterDate = new DateTime(2014, 12, 15, 21, 0, 0);
DateTime leaveDate = new DateTime(2014, 12, 16, 11, 0, 0);

TimeSpan duration = leaveDate.Subtract(enterDate);

double workingHours = duration.TotalHours;


这篇关于他工作了几个小时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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