18
votes

From DateTimeFormatter javadoc:

Zone names: Time zone names ('z') cannot be parsed.

Therefore timezone parsing like:

System.out.println(new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy").parse("Fri Nov 11 12:13:14 JST 2010"));

cannot be done in Joda:

DateTimeFormatter dtf = DateTimeFormat.forPattern("EEE MMM dd HH:mm:ss z yyyy");
System.out.println(dtf.parseDateTime("Fri Nov 11 12:13:14 JST 2010"));
//Exception in thread "main" java.lang.IllegalArgumentException: Invalid format: "Fri Nov 11 12:13:14 JST 2010" is malformed at "JST 2010"
//at org.joda.time.format.DateTimeFormatter.parseDateTime(DateTimeFormatter.java:673)
3
I just wanted to say "F#$% JodaTime!" Okay, not really; it's saved my butt more than a few times. But I REALLY wish they would update their documentation. I spent an hour trying to figure out why this wasn't working. The Javadoc for DateTimeFormat has "z -- time zone text -- Pacific Standard Time; PST". But then, a few paragraphs later on the same page, "Zone names: Time zone names ('z') cannot be parsed." Way to go JodaTime... put it in the small print. No big deal. I just lost 5 years of my life and most of my hair. ;) - The Awnry Bear
@TheAwnryBear - and ... hopefully ... learned a couple of lessons: 1) that timezone abbreviations are EVIL, and 2) that you need to read the javadoc properly :-). - Stephen C
Hehe, agreed Stephen. :) I tend to skimp, which works 95-99% of the time... then you run into situations like with the Joda docs. :P - The Awnry Bear

3 Answers

14
votes

I think that the reason is that 'z' timezone names are conventional (not standardized) and ambiguous; i.e. they mean different things depending on your country of origin. For example, "PST" can be "Pacific Standard Time" or "Pakistan Standard Time".

If you are interested, this site has a listing of a large number of timezone names. It is not difficult to spot cases where there is ambiguity.

5
votes

Probably because some time zone abbreviations are ambiguous and the parser can't know which time zone is meant.

It might of course also be one of the tiny, strange ticks and missing features you find after working with Joda for a while.

3
votes

Abbreviated time zones are indeed ambiguous and Joda took a step further removing support for them as stated in the DateTimeZone javadoc: