为什么Joda DateTimeFormatter无法解析时区名称('z') [英] Why Joda DateTimeFormatter cannot parse timezone names ('z')

查看:162
本文介绍了为什么Joda DateTimeFormatter无法解析时区名称('z')的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

来自 DateTimeFormatter javadoc


区域名称:无法解析时区名称('z')。

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

因此,时区解析如:

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

无法在Joda中完成:

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)


推荐答案

我认为原因是'z'时区名称是传统的(非标准化)和含糊不清的;即根据您的原籍国,它们意味着不同的东西。例如,PST可以是太平洋标准时间或巴基斯坦标准时间。

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.

这篇关于为什么Joda DateTimeFormatter无法解析时区名称('z')的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆