【发布时间】:2014-01-18 18:17:03
【问题描述】:
我在比较两个 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>
有人知道我在这里缺少什么吗?
顺便说一句,如果您想知道为什么 DateTime 显示在 GMT+1:00 区域,因为这是我希望我的 DateTime 对象默认使用的时区。
谢谢!
【问题讨论】:
-
尝试比较它们的毫秒值。调试会让你走得更远。
-
是的,比较millis返回它们是相等的,但这也应该有效 - 对吧?
-
getCreationDate()返回的值是什么类型? -
org.joda.time.DateTime
-
你能用
println(response.getCreationDate.getClass())确认吗?我没有发现其他任何问题。