Asp.net中的时差计算 [英] Time Difference Calculation in Asp.net
问题描述
我在asp.net页面中创建了一个ajax计时器。它显示当前时间,以短时间格式(上午9:33)及其运行。
当我点击按钮时,显示当前时钟时间在文本框上,在另一个按钮上单击当前时间显示在另一个文本框中。
例如,如果第一个文本框中的值是9:23,第二个文本框是9:30;如何计算时差?
9:30 - 9:23 = 0:07
帮我找时差。
I created an ajax timer in a asp.net page. It''s showing current time, in the short time format (9:33 AM) and its running.
When I clicked on a button, current clock time displays on a textbox, and on another button click the current time displays in another textbox.
For example if the value in the first textbox is 9:23 and second textbox is 9:30; How can I calculate the time difference?
9:30 - 9:23 = 0:07
Help me to find the time difference.
推荐答案
结构System.DateTime
有-
(减法运算符)定义,返回类型是System.TimeSpan
。
请参阅 http://msdn.microsoft.com/en-us/library/system。 datetime.aspx [ ^ ]。
这应该足够了。
-SA
The structureSystem.DateTime
has "-
" (subtraction operator) defined, return type isSystem.TimeSpan
.
See http://msdn.microsoft.com/en-us/library/system.datetime.aspx[^].
This should be more then enough.
—SA
Hi,
DateTime dateTime1 = Convert.ToDateTime("9:30");
DateTime dateTime2 = Convert.ToDateTime("9:23");
TimeSpan timeSpan=dateTime1.Subtract(dateTime2);
注意:由于时间字符串没有AM或PM,转换将把它视为一个24小时的时钟
Note: As the time string don''t have AM or PM the conversion will take it as a 24 hr clock
Hope 两个日期之间如何发现差异 [ ^ ]也可以帮助你。
Hope How-find-difference-between-two-Dates[^]may also help you.
这篇关于Asp.net中的时差计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!