19

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)
JodaStephen
  • 60,927
  • 15
  • 95
  • 117
dimitrisli
  • 20,895
  • 12
  • 59
  • 63
  • 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 Oct 07 '12 at 06:02
  • 2
    @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 Nov 14 '12 at 01:40
  • 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 Nov 19 '12 at 20:49

3 Answers3

15

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.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
  • Btw, Pakistan Standard Time is PKT ;) http://www.timeanddate.com/library/abbreviations/timezones/asia/pkt.html – Kaitsu Nov 13 '12 at 11:53
  • 1
    @Kaitsu - according the site I linked to, PST is Pakistan Standard Time too. That's the problem - the names are NOT STANDARDIZED. The JodaTime designers have taken the sensible view that since they are not standardized, and they are ambiguous, there is no sensible way to support them that will work in the international context. – Stephen C Nov 14 '12 at 01:34
  • It could at least parse something like "UTC" and "GMT" ? since those are very common. – chakrit Jul 29 '13 at 10:46
  • @chakrit - very common != standard, and if you start accepting some of them, you run into the problems of the ones that are ambiguous. – Stephen C Mar 19 '14 at 10:40
  • What is the standard to indicate the TimeZone? – Shajeel Afzal Aug 10 '15 at 15:34
  • The only standard is the ISO date / time standard where the timezone is indicated by an hours:minutes offset from UTC. However, you could the time zone >>names<< from here: http://www.iana.org/time-zones. – Stephen C Aug 10 '15 at 22:20
5

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.

Joe
  • 46,419
  • 33
  • 155
  • 245
jarnbjo
  • 33,923
  • 7
  • 70
  • 94
3

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

JodaStephen
  • 60,927
  • 15
  • 95
  • 117
Carlos Ferreyra
  • 275
  • 3
  • 10