如何在asp.netc#中获取开始时间和结束时间之间的差异(以秒为单位) [英] how to get difference between start time and end time in seconds in asp.netc#
本文介绍了如何在asp.netc#中获取开始时间和结束时间之间的差异(以秒为单位)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请告诉我如何在asp.netc中获得开始时间和结束时间之间的差异(以秒为单位)#我的代码是
Pls some one tell that how to get difference between start time and end time in seconds in asp.netc# my code is
Label5.Text = DateTime.Now.ToLongTimeString();
DateTime startTime, endTime;
startTime = Convert.ToDateTime(Label5.Text);
endTime = Convert.ToDateTime(Label5.Text);
var timeDiff = new TimeSpan(endTime.Ticks - startTime.Ticks);
Label6.Text = Convert.ToString(timeDiff);
请告诉我们如何在几秒钟内区别对待...
pls tell how to take diffeence in seconds...
推荐答案
TimeSpan t = endTime - startTime ;
Label6.Text = Convert.Tostring(t.Seconds);
DateTime startTime,endTime;
startTime = Convert.ToDateTime(DateTime.Now.ToLongTimeString());
endTime = Convert.ToDateTime(DateTime.Now.ToLongTimeString());
var timeDiff = new TimeSpan(endTime.Ticks-startTime.Ticks).秒
MessageBox.Show(Convert.ToString(timeDiff));
使用属性.第二,您将获得所需的!
DateTime startTime, endTime;
startTime = Convert.ToDateTime(DateTime.Now.ToLongTimeString());
endTime = Convert.ToDateTime(DateTime.Now.ToLongTimeString());
var timeDiff = new TimeSpan(endTime.Ticks - startTime.Ticks).Seconds
MessageBox.Show(Convert.ToString(timeDiff));
use the property .Seconds you will get the desired!
有两个属性可用于区分秒数.请参见以下代码作为示例:
There are two properties for the difference in Seconds. Please see this code for an example:
private void GetTimeDiff()
{
DateTime startTime = DateTime.Parse("08:30:18");
DateTime endTime = DateTime.Parse("17:15:19");
TimeSpan t = endTime - startTime;
MessageBox.Show(t.Seconds.ToString()); //shows "1"
MessageBox.Show(t.TotalSeconds.ToString()); //shows "3501"
}
根据您的需要,可以使用属性"Seconds"或"TotalSeconds".
Depending on what you want, you may use the properties "Seconds" or "TotalSeconds".
这篇关于如何在asp.netc#中获取开始时间和结束时间之间的差异(以秒为单位)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文