Java判断时间是否大于X分钟
我知道如何使用日期函数确定时间戳是否“大于”“等于”或“小于”,但我不知道如何确定比时间大多少,
例如,我将如何告诉下午 6:15 比下午 6:00 多 15 分钟
我有一个想法,将时间转换为毫秒,并与当前时间(以毫秒为单位)进行比较,但现在潜在想法的迷雾,
赞赏洞察力
I know how to determine IF a time stamp is "greater than" "equal to" or "less than" using the date function, but I don't know how to determine HOW MUCH greater than a time is
for instance, how would I tell that 6:15 PM is 15 minutes greater than 6:00 PM
I've got an idea to convert times into milliseconds and compare with the current time in milliseconds, but its a fog of potential ideas right now
insight appreciated
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请参阅如何转换-毫秒-to -x-mins-x-seconds-in-java
然后你可以做这样的事情...
另外,看看 Joda 在某个时候。它几乎是 Java 中更好的日期和时间函数的事实上的标准。他们有一些很好的便捷方法,例如
Minutes.minutesBetween(date1,date2)
see how-to-convert-milliseconds-to-x-mins-x-seconds-in-java
Then you can do something like this...
Also, take a look at Joda at some point. It's pretty much the de-facto standard for better date and time functions in java. They have some nice convenience methods like
Minutes.minutesBetween(date1,date2)
只需创建两个所需的日期戳并转换为毫秒,然后将它们相减并返回差值。
Just create two date stamps you want and convert into milliseconds and subract them and return the difference.