2
A
回答
0
这是我能拿出最好的:
public static boolean passesTime(LocalDateTime start,
LocalDateTime end,
LocalTime time) {
// If the duration is more than a day, any time will be passed.
if (Duration.between(start, end).toDays() >= 1)
return true;
// Otherwise, the time has to be passed on the start day...
LocalDateTime timeOnStartDay = LocalDateTime.of(start.toLocalDate(), time);
if (timeOnStartDay.isAfter(start) && timeOnStartDay.isBefore(end))
return true;
// or on the end day.
LocalDateTime timeOnEndDay = LocalDateTime.of(end.toLocalDate(), time);
if (timeOnEndDay.isAfter(start) && timeOnEndDay.isBefore(end))
return true;
return false;
}
与java.time
API测试。如果您使用Joda时间,代码应该相似(如果不相同)。
相关问题
- 1. 检查时区是否已经过了一定时间
- 2. 如何检查一个时间戳是否是整小时
- 3. 如何检查当前时间是否在一段时间内?
- 4. 如何检测PHP/MySQL中是否已经过了一段时间?
- 5. 检查日期时间字段是否通过当前时间戳
- 6. 检查一个时区中的时间是否已经过了php?
- 7. 如何检查时间戳是否超过特定月数?
- 8. 检查时间戳是否在tsrange内
- 9. 如何检查当前时间是否在oracle的两个时间戳之间
- 10. 如何检查给定的时间戳是否10分钟?
- 11. 检查时间戳字符串是一个时间范围
- 12. 检查自创建时间变量以来的时间是否已经过去
- 13. Javascript检查它是否从一定时间过去了午夜
- 14. 检查时间戳是否超过30秒
- 15. Javascript:如何检查时间戳是否属于当前日期?
- 16. 总结时间戳之间的经过时间SQL Server
- 17. 如何检查是否与时区日期时间已经过去
- 18. 检查用户是否通过unix时间戳记登录了10分钟
- 19. Java if语句currentTimeMillis,检查是否已经过了特定的时间
- 20. 检查TSA时间戳
- 21. 如何确定NSDate(包括时间)是否已经过去
- 22. Perl检查一个字符串是否包含mysql时间戳
- 23. 检查时间是否已经越过PHP
- 24. MySQL检查自日期时间以来是否已经过去了1分钟
- 25. 检查行是否是Python中的时间戳
- 26. 时间戳列 - 是否可以查询?
- 27. 如何确定一个时间戳在postgresql中是否在另一个时间戳之前?
- 28. 如何检查timepicker1时间是否比timepicker2时间早?
- 29. 检查当前时间距“last_updated”时间是否超过一个小时
- 30. 查看时间戳是否在特定小时之间
'if(start midnight)'(伪代码)怎么办?提示:使用方法'isBefore'和'isAfter'。 –
Thomas
2014-11-04 10:47:13
所有时间戳在午夜之前和午夜之后。 – aioobe 2014-11-04 10:48:24
检查JodaTime或日历以获得日期时间方便。 – Dmytro 2014-11-04 10:51:47