我有两个使用datetimepicketr的tex框,我需要登录和注销时间之间的代码差异 [英] i have two tex boxes using datetimepicketr i need code diff between login and logout time

查看:52
本文介绍了我有两个使用datetimepicketr的tex框,我需要登录和注销时间之间的代码差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用代码来获取登录和注销时间之间的差异。我使用datetimepicker控件来选择日期和时间,但我只得到了几天的差异,但我能够得到时差。

我有两个tex框,比如starttime和endtime,使用datetimepicker我需要代码来获取时间差异hh:min:sec可以任何人告诉我代码。

解决方案

< blockquote>这个时间差称为时间跨度( System.TimeSpan 结构)并使用'' - ''运算符进行计算,而不是太惊讶。我几乎无法理解你怎么能错过它。它可能是这样的:

 System.DateTime login = System.DateTime.Now; 

// 记住这一点......

// 一段时间之后
System.DateTime logout = System.DateTime.Now;

System.TimeSpan timeSpan = logout - login;
// 依此类推





我看不出为什么你需要一个 DateTimePicker ,但如果你需要,它的价值也是 System.DateTime的。从概念上讲,没有日期和时间,只有时间。只有您不应该单独使用这些结构的成员。他们有一切可以计算你需要的东西。



http:// msdn。 microsoft.com/en-us/library/system.datetime.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/system.timespan.aspx [ ^ ]。



-SA

I need code for getting difference between login and logout time.i used datetimepicker control for selecting date and time but i am getting only days difference but i''m nt able to get the time difference.
I have two tex boxes like starttime and endtime by using datetimepicker i need code for getting time diff in hh:min:sec can any one tell me the code.

解决方案

This time difference is called Time Span (System.TimeSpan structure) and is calculated, not to much of surprise, using ''−'' operator. I hardly can understand how could you miss it. It could be like this:

System.DateTime login = System.DateTime.Now;

// remember this point ...

// some time later
System.DateTime logout = System.DateTime.Now;

System.TimeSpan timeSpan = logout - login;
// and so on



I cannot see why would you need a DateTimePicker here, but if you need, it also has the value of System.DateTime. Conceptually, there is no date and time, there is only time. Only you should not work with members of these structures separately. They have everything to calculate what you need.

http://msdn.microsoft.com/en-us/library/system.datetime.aspx[^],
http://msdn.microsoft.com/en-us/library/system.timespan.aspx[^].

—SA


这篇关于我有两个使用datetimepicketr的tex框,我需要登录和注销时间之间的代码差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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