Kenny MacLeod wrote:
> Folks,
>
> Take this simple unit test:
>
> DateTimeFormatter parser = ISODateTimeFormat.dateTimeParser();
> DateTime time1 = new DateTime(2007,11,22,7,0,42,0,DateTimeZone.UTC);
> DateTime time2 = parser.parseDateTime("2007-11-22T07:00:42Z");
>
> assertEquals(time1, time2);
>
>
> This fails, apparently because each DateTime instance contains a
> different instance of ISOChronology. time1 contains the static
> DateTimeZone.UTC instance, and the parsed time2 contains an instance
> manually assembled by the parser. Now, ISOChronology has no equals()
> method defined, nor do any of its superclasses, and so the equals
> comparison fails.
The parsed ISOChronology will match that of the default time zone. To
parse the 'Z' and get UTC you need to call withOffsetParsed():
DateTime time2 =
parser.withOffsetParsed().parseDateTime("2007-11-22T07:00:42Z");
Stephen
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Joda-interest mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/joda-interest