时间间隔为24小时格式 [英] Diffrence between time in 24 hour format

查看:141
本文介绍了时间间隔为24小时格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



由于某种原因我想计算时差,但它是24小时格式。



示例

21:15和3:20这两者之间的差异是6小时5分钟



同样像3:20到21:25 18小时5分钟。



任何人都可以帮助我。

Hi,
for some reason i want to calculate time difference but it is in 24 hour format.

Example
21:15 And 3:20 Difference between these two is 6 hour 5 minutes

Same like 3:20 to 21:25 18 hour 5 min.

Could anyone help me.

推荐答案

你可以减去你的DateTime对象。您无需考虑DateTime实例的格式或格式。
You can just subtract your DateTime objects. No need for you to think in which way the DateTime instances were or will be formatted.


使用此





use this


string s = DateTime.ParseExact("2130", "HHmm", CultureInfo.CurrentCulture).ToString("hh:mm tt");
TimeSpan span = new TimeSpan(0, 2, 0, 30, 0);
s = DateTime.ParseExact("2130", "HHmm", CultureInfo.CurrentCulture).Subtract(span).ToString("hh:mm tt");
Response.Write(s);


推荐



Refer

DateTime dateTime1 = Convert.ToDateTime("9:30");
      DateTime dateTime2 = Convert.ToDateTime("18:30");
      TimeSpan timeSpan = dateTime1.Subtract(dateTime2);
      lblTime.Text = timeSpan.ToString();


这篇关于时间间隔为24小时格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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