Why Joda DateTimeFormatter cannot parse timezone names ('z')

拟墨画扇 提交于 2019-11-27 02:42:25

问题


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)

回答1:


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.




回答2:


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:


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



来源:https://stackoverflow.com/questions/4498274/why-joda-datetimeformatter-cannot-parse-timezone-names-z

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!