[英]TimeZone broken in SimpleDateFormat in android 2.3
Android 2.3 was recently released last night. 昨晚发布了Android 2.3。 So naturally I tried my app on it and found there was date formatting issue.
所以自然地,我尝试了我的应用程序,发现存在日期格式问题。 I have noticed the DateFormatter produces different formats.
我注意到DateFormatter产生不同的格式。 So do this in a simple Java program:
因此,可以在一个简单的Java程序中执行此操作:
((SimpleDateFormat)DateFormat.getDateTimeInstance(DateFormat.LONG,
DateFormat.LONG)).format(new Date());
Output is 输出是
December 7, 2010 11:49:40 AM EST
2010年12月7日,美国东部标准时间上午11:49:40
Do the same thing in an android emulator and you get 在android模拟器中做同样的事情,你会得到
December 7, 2010 11:42:50 AM GMT-05:00
2010年12月7日上午11:42:50 GMT-05:00
Notice the different time zone. 请注意不同的时区。 Has anybody ran in to this issue?
有人遇到过这个问题吗? Is there another formatter I can use that doesn't depend on Java's implementation?
我可以使用另一种不依赖Java实现的格式化程序吗?
EDIT: Ok so here is more detail to why I think this is broken: 编辑:好的,所以这是为什么我认为这是坏的更多细节:
Using this code: 使用此代码:
private final DateFormat format =
new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z");
I tried to parse a date but the following error is thrown: 我试图解析日期,但抛出以下错误:
12-07 12:55:49.556: ERROR/DateDeserializer(847): Error when parsing date
java.text.ParseException: Unparseable date: "Mon, 06 Dec 2010 17:13:35 EST"
at java.text.DateFormat.parse(DateFormat.java:626)
at com.currency.mobile.client.DateDeserializer
.deserialize(DateDeserializer.java:31)
at com.currency.mobile.client.DateDeserializer
.deserialize(DateDeserializer.java:19)
at org.codehaus.jackson.map.deser.SettableBeanProperty
.deserialize(SettableBeanProperty.java:149)
两者都是相同的TimeZone,只是表示形式不同
There is nothing wrong with the output. 输出没有问题。 You create a DateFormat -Instance which depends on the default Locale .
您创建一个DateFormat -Instance,它取决于默认的Locale 。 It is not unusual that on different machines, different java-installations the default Locale vary and so the output of locale-dependent operations.
在不同的机器上,不同的Java安装,默认的语言环境会有所不同,因此与语言环境相关的操作的输出也很常见。 In this case the default TimeZone is different, but the two outputs in your question represent the same Date, printed with the same format String
MMMMM d, yyyy hh:mm:ss az
. 在这种情况下,默认的TimeZone是不同的,但是问题中的两个输出表示相同的Date,并以相同的格式String
MMMMM d, yyyy hh:mm:ss az
打印。
UPDATE: parse() in Android 2.3 will work with TimeZones like GMT+xxxx
etc, but it doesn't recognize EST
for example as a valid TimeZone for parsing. 更新: Android 2.3中的parse()可以与TimeZone(例如
GMT+xxxx
等)一起使用,但是例如,它不能将EST
识别为有效的TimeZone进行解析。 Android knows about EST
if you use TimeZone.getTimeZone("EST")
. 如果您使用
TimeZone.getTimeZone("EST")
Android就会了解EST
。
UPDATE2: UPDATE2:
Three-letter timezone IDs "EST", "HST", and "MST" are deprecated. 不建议使用三个字母的时区ID“ EST”,“ HST”和“ MST”。 Do not use them.
不要使用它们。
Looks like support for pattern "EEE MMM dd HH:mm:ss zzz yyyy" is also broken. 似乎对模式“ EEE MMM dd HH:mm:ss zzz yyyy”的支持也已损坏。
Evgueni 叶夫根尼·
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.