检查一个日期是否完全是24小时或更久 [英] Check if one date is exactly 24 hours or more after another
问题描述
我在Java中使用compareTo方法来尝试检查某个日期是否大于或等于另一个日期之后的24小时。
如何确定什么整数比较日期?
答案取决于你想要实现什么。
一种方法可能是以毫秒为单位检查差异。 24小时以毫秒计算可以通过
24 * 60 * 60 * 1000 = 86400000
h min sec millis
(在代码中你也可以写 TimeUnit.HOURS.toMillis(24) code>哪个IMO更具描述性)
所以现在你可以检查两个日期之间的差异(以毫秒表示)大于86400000。 >
I am using the compareTo method in Java to try and check if a certain date is greater than or equal than 24 hours after another date.
How do I determine what integer to compare the date to?
Answer depends on what you want to achieve.
One way, could be checking difference in milliseconds. 24 h in milliseconds can be calculated via
24 * 60 * 60 * 1000 = 86400000
h min sec millis
(in code you can also write TimeUnit.HOURS.toMillis(24)
which IMO is more descriptive)
So now you can just check if difference between two dates (expressed in milliseconds) is greater then 86400000.
这篇关于检查一个日期是否完全是24小时或更久的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!