Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
JodaTime 中是否有 API 方法可以查看 DateTime 是否在 [start, end] 内,即包含边界?
我发现的唯一一件事是 new Interval(start, end).contains(dateTime) 但如果 dateTime 等于 end,这似乎是错误的。
如果您需要经常这样做,最简单的方法是创建一个新的间隔,将旧的间隔延长一毫秒:
Interval inclusiveInterval = interval.withEndMillis(interval.getEndMillis() + 1);
或者只是使用
if (interval.contains(dateTime) || interval.getEnd().isEqual(dateTime))
(该isEqual方法忽略了年表和时区。)
isEqual