Java 比较两个joda DateTime实例

Java 比较两个joda DateTime实例,java,datetime,jodatime,Java,Datetime,Jodatime,我在比较两个DateTime对象时遇到问题 System.out.println(response.getCreationDate().toString()); // will return "2013-12-31T22:59:21.000+01:00", but... assertThat(response.getCreationDate(), equalTo(new DateTime("2013-12-31T22:59:21+01:00"))); // will throw an asse

我在比较两个DateTime对象时遇到问题

System.out.println(response.getCreationDate().toString()); // will return "2013-12-31T22:59:21.000+01:00", but...

assertThat(response.getCreationDate(), equalTo(new DateTime("2013-12-31T22:59:21+01:00"))); // will throw an assertation error with the following error

Expected: <2013-12-31T22:59:21.000+01:00>
 but: was <2013-12-31T22:59:21.000+01:00>
System.out.println(response.getCreationDate().toString());//将返回“2013-12-31T22:59:21.000+01:00”,但。。。
断言(response.getCreationDate(),equalTo(新日期时间(“2013-12-31T22:59:21+01:00”);//将抛出带有以下错误的assertation错误
预期:
但是:是吗
有人知道我错过了什么吗

顺便说一句,如果您想知道为什么DateTime显示在GMT+1:00区域,因为我希望DateTime对象默认显示在该时区


谢谢

DateTime
AbstractInstant
继承其
equals
方法。它是这样实现的

public boolean equals(Object readableInstant) {
    // must be to fulfil ReadableInstant contract
    if (this == readableInstant) {
        return true;
    }
    if (readableInstant instanceof ReadableInstant == false) {
        return false;
    }
    ReadableInstant otherInstant = (ReadableInstant) readableInstant;
    return
        getMillis() == otherInstant.getMillis() &&
        FieldUtils.equals(getChronology(), otherInstant.getChronology());
}
请注意最后一行比较年表。您的实例的时间顺序可能不同。

此代码(示例):

将打印:

2013-12-31T16:59:21.000-05:00
2013-12-31T16:59:21.000-05:00
false

您可能正在比较两个日期相同但不同的。

尝试比较它们的毫秒值。调试将使您走得更远。是的,比较millis返回值是否相等,但这也应该有效-对吗?由
getCreationDate()
?org.joda.time.datetime返回的值是什么类型的?请使用
println(response.getCreationDate.getClass())
?我没有发现任何其他错误。如果我提取这两个datetime对象的年表,我会得到以下结果:
ISOChronology[+01:00]
ISOChronology[Europe/贝尔格莱德]
,但贝尔格莱德的时间是GMT+1:00。@SpaseMarkovski,开始了。年表并不等同于时区,但它们不一样吗?欧洲/贝尔格莱德的时间是格林尼治标准时间+1:00。@SpaseMarkovski这不是唯一的目的。
2013-12-31T16:59:21.000-05:00
2013-12-31T16:59:21.000-05:00
false