我正在使用 jodatimeDateTime变量。我想检查 DateTime 'x' 是否在 DateTime 'y' 之后。isAfter 函数只接受一个long参数,而不是 a DateTime,我觉得这很奇怪。比较两个DateTimes 的最佳方法是什么?
18842 次
4 回答
23
ReadableInstant 中有一个方法boolean isAfter(ReadableInstant instant),因此 DateTime 实现 ReadableInstant 它也应该接受 DateTime。
于 2013-08-30T11:53:50.557 回答
3
方法 isAfter 说明
public boolean isAfter(ReadableInstant instant)
Is this instant after the instant passed in comparing solely by millisecond.
Specified by:
isAfter in interface ReadableInstant
Parameters:
instant - an instant to check against, null means now
Returns:
true if the instant is after the instant passed in
它需要ReadableInstant作为参数,因此DateTime也可以清楚地从DateTime Hierarchy
Class DateTime
java.lang.Object
extended by org.joda.time.base.AbstractInstant
extended by org.joda.time.base.AbstractDateTime
extended by org.joda.time.base.BaseDateTime
extended by org.joda.time.DateTime
All Implemented Interfaces:
Serializable, Comparable<ReadableInstant>, ReadableDateTime, ReadableInstant
以上细节取自joda api docs
于 2013-08-30T12:11:00.950 回答
1
public static void main(String[] args) {
System.err.println(new DateTime().isAfter(new DateTime().plusDays(1)));
}
为我工作
于 2013-08-30T11:55:53.997 回答
1
还有一个getMillis()继承自的方法,BaseDateTime它为您提供一个long表示日期的值,您可以比较这两个long值以确定哪个在之前以及多少。
于 2013-08-30T11:57:55.473 回答