我有两个JodaTime对象,我想要这样的方法
// Return the latest of the two DateTimes
DateTime latest(DateTime a, DateTime b)但我找不到这样的东西。我可以轻松地编写它,但我确信JodaTime会把它放在某个地方。
发布于 2014-05-11 22:58:29
DateTime实现了Comparable,因此除了执行以下操作之外,不需要滚动您自己的:
DateTime latest(DateTime a, DateTime b)
{
return a.compareTo(b) > 0 ? a : b;
}或者直接使用JodaTime API (考虑到Chronology与compareTo不同):
DateTime latest(DateTime a, DateTime b)
{
return a.isAfter(b) ? a : b;
}发布于 2016-04-25 14:27:31
正如杰克所指出的,DateTime实现了Comparable。如果您使用的是番石榴,则最大两个日期(例如a和b)可以通过以下速记确定:
Ordering.natural().max(a, b);https://stackoverflow.com/questions/23598758
复制相似问题