获得两个值之间的时间差 [英] Getting time difference between two values
本文介绍了获得两个值之间的时间差的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的应用我有4个文本框,和2文本框输入开始时,和2文本框输入结束时间。
In my application I have 4 TextBoxes, and 2 TextBoxes to enter the start-time, and 2 TextBoxes to enter end-time.
用户总会进入一个完整的时间,所以输入将永远是11点30分,12点45分,依此类推。
The user will always enter a completed time, so the input will always be 11:30, 12:45, and so on.
我怎样才能在开始和结束时间的小时和分钟的区别吗?
How can I get the difference in hours and minutes between start and endtime?
推荐答案
使用TimeSpan类和减去日期时间的方法。
Use TimeSpan class, and Subtract method of DateTime.
DateTime t1 = Convert.ToDateTime(textBox1.Text);
DateTime t2 = Convert.ToDateTime(textBox2.Text);
TimeSpan ts = t1.Subtract(t2);
这篇关于获得两个值之间的时间差的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文