Here is the only correct answer found by our own testing:
DateTime a = new DateTime(); // uses default time zone System.out.println(a); // 2014-01-08T19:38:00.696+01:00 DateTime b = DateTime.parse(a.toString()); System.out.println(b); // 2014-01-08T19:38:00.696+01:00 System.out.println(a.getChronology()); // ISOChronology[Europe/Berlin] System.out.println(b.getChronology()); // ISOChronology[+01:00] System.out.println(a.equals(b)); // false!!!
I assumed that in Scala, comparison with == really means comparison with equals (), as indicated in his comment by @ aris1348880, so I replaced the operator in the translation with java code, respectively.
Thus, the reason for the unsuccessful equality () - the comparison is obvious: this is the identifier of the time zone that is incorrectly printed in the toString() method of DateTime a . I consider this a bug in JodaTime because toString() should always print the entire state of the object's immutable value. By the way, in this detail the old java.util.Date even worse! Well, since the work is around, you can use the JodaTime formatting mechanism to print correctly. A.
System.out.println( DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'['ZZZ']'").print(a));
To make the behavior more understandable:
The DateTime constructor uses the default time zone (in my Europe / Berlin test). Its toString () method prints the offset instead, not the real timezone (this is a problem).
The DateTime-parse () method uses, according to the JodaTime documentation, ISODateTimeFormat # dateTimeParser () , which again can only analyze offsets, but in this code it was also using only biased information, and not with a real time zone, otherwise parsing would stop with an exception.
In both cases, DateTime instances are created in different ways with different time zones / offsets and, therefore, with different chronologies. Thus, equals () - the result at first glance is amazing, but understandable.