两个日期的小时和分钟之间的时差 [英] Difference between two dates hours and minutes

查看:86
本文介绍了两个日期的小时和分钟之间的时差的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取两个日期之间的小时和分钟差异.我有所不同,但是当我想在这两个日期之间有所不同时.返回0.下午5:50. 2010年7月31日和上午5:50. 2010年8月1日.

How to get hours and minutes difference between two dates. I have got the difference, but when I want to get difference between this two dates. It returns 0. For ex. 5:50 pm. 31,july,2010 and 5:50 am. 1,august,2010.

推荐答案

DateTime date1 = new DateTime(2010, 7, 31, 17, 50, 0);
DateTime date2 = new DateTime(2010, 8, 1, 17, 50, 0);
TimeSpan diff = date2 - date1;
Console.WriteLine("{0}:{1}:{2}",diff.TotalHours, diff.Minutes, diff.Seconds);


听起来您正在使用.compareTo()?这实现了 IComparable ,它将解释0结果.

您需要什么结果?滴答的区别?秒?分钟?
It sounds like you are using .compareTo()? This implements IComparable which would explain the 0 result.

What result do you require? The difference in ticks? Seconds? Minutes?


这篇关于两个日期的小时和分钟之间的时差的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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