I have a problem with the comparing two DateTime objects.
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>
Anyone has an idea what am I missing here?
Btw, if you are wondering why the DateTime is displayed in GMT+1:00 zone, cause that's the timezone in which I want my DateTime objects to be by default.
Thanks!
This code (example) :
Chronology ch1 = GregorianChronology.getInstance(); Chronology ch2 = ISOChronology.getInstance(); DateTime dt = new DateTime("2013-12-31T22:59:21+01:00",ch1); DateTime dt2 = new DateTime("2013-12-31T22:59:21+01:00",ch2); System.out.println(dt); System.out.println(dt2); boolean b = dt.equals(dt2); System.out.println(b);
Will print :
2013-12-31T16:59:21.000-05:00 2013-12-31T16:59:21.000-05:00 false
You are probably comparing two DateTimes with same date but different Chronology.
Source: Stackoverflow.com