必须在windows c#中计算两个时间的差异 [英] Have to calculate difference of two Time in windows c#

查看:105
本文介绍了必须在windows c#中计算两个时间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在数据库中我有两个名为In1和Out1数据类型的字段作为varchar(50)



In1 = 9:30 AM

Out1 = 11:00 Am



i必须计算上述两者的差异。该怎么办?



请帮帮我

In database i have two field called In1 and Out1 datatype as varchar(50)

In1 = 9:30 AM
Out1 = 11:00 Am

i have to calculate difference of above two. how to do it??

please help me

推荐答案

你可以用timespan [ ^ ]计算c#中的时差。

看看:

You can use timespan[^] to calculate time diff in c#.
Have a look:
DateTime dt1=Textbox1.Text; 
DateTime dt2=Textbox2.Text; 

TimeSpan t=dt2.Subtract(dt1);

string diff = t.Hours.ToString()+":"+t.Minutes.ToString() + ":" + t.Seconds.ToString();


C#时差计算 [ ^ ]

如何计算两个不同日期和时间之间的差异 [ ^ ]

http://www.dotnetspider.com/forum/217151-Time-difference-c.aspx [ ^ ]

http://www.c-sharpcorner.com/Forums/Thread/103423/ [ ^ ]
C# Time difference calculation[^]
how to calculate difference between two different date and time[^]
http://www.dotnetspider.com/forum/217151-Time-difference-c.aspx[^]
http://www.c-sharpcorner.com/Forums/Thread/103423/[^]


您好,



尝试下面的代码。

Hi,

Try below code.
DateTime dt1 = DateTime.ParseExact(In1, "HH:mm:ss", new DateTimeFormatInfo());
DateTime dt2 = DateTime.ParseExact(Out1, "HH:mm:ss", new DateTimeFormatInfo());
TimeSpan ts = dt1.Subtract(dt2);



欲了解更多信息,请参阅以下链接。

http://www.dotnetspider.com/forum/217151-Time-difference-c.aspx [< a href =http://www.dotnetspider.com/forum/217151-Time-difference-c.aspxtarget =_ blanktitle =New Window> ^ ]


这篇关于必须在windows c#中计算两个时间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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