如何比较日期时间的时间部分 [英] How to compare time part of datetime
本文介绍了如何比较日期时间的时间部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
让我们说我们有
DateTime t1 = DateTime.Parse("2012/12/12 15:00:00.000");
和
DateTime t2 = DateTime.Parse("2012/12/12 15:03:00.000");
如何在C#中比较和说哪个时间晚于?
How to compare it in C# and say which time is "is later than"?
谢谢!
推荐答案
您可以使用的的TimeOfDay 财产和使用比较的反对。
You can use the TimeOfDay property and use the Compare against it.
TimeSpan.Compare(t1.TimeOfDay, t2.TimeOfDay)
每文档:
-1 if t1 is shorter than t2.
0 if t1 is equal to t2.
1 if t1 is longer than t2.
这篇关于如何比较日期时间的时间部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文