0

我正在尝试调试与时区解析的一些不一致,SimpleDateFormat这里是日期格式,我用来解析:

static private final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd, h:mmaa zzz", Locale.US);

要解析的日期字符串:

2013-03-20,美国东部时间下午 3:36

三星 2.3.5 解析失败适用于 HTC 4.0.4 和 HTC 2.3.3。

以下是一些解析测试的输出:

宏达电 4.0.4:

Test : 2013-03-20, 3:36PM EST : Wed Mar 20 21:36:00 CET 2013 : lenient : true
Test : 2013-03-20, 3:36PM EDT : Wed Mar 20 20:36:00 CET 2013 : lenient : true
Test : 2013-03-20, 3:36PM EST : Wed Mar 20 21:36:00 CET 2013 : lenient : false
Test : 2013-03-20, 3:36PM EDT : Wed Mar 20 20:36:00 CET 2013 : lenient : false

宏达电 2.3.3:

Test : 2013-03-20, 3:36PM EST : Wed Mar 20 21:36:00 GMT+01:00 2013 : lenient : true
Test : 2013-03-20, 3:36PM EDT : Wed Mar 20 20:36:00 GMT+01:00 2013 : lenient : true
Test : 2013-03-20, 3:36PM EST : Wed Mar 20 21:36:00 GMT+01:00 2013 : lenient : false
Test : 2013-03-20, 3:36PM EDT : Wed Mar 20 20:36:00 GMT+01:00 2013 : lenient : false

三星 2.3.5:

Test : 2013-03-20, 3:36PM EST : Wed Mar 20 21:36:00 GMT+01:00 2013 : lenient : true
Test : 2013-03-20, 3:36PM EST : Wed Mar 20 21:36:00 GMT+01:00 2013 : lenient : false

其余的解析在三星上失败。

任何人都可以解释这种行为吗?

4

3 回答 3

1

There is no JDK available on Android at the moment.

And looking at the reference of SimpleDateFormat there is only one version of it. so whatever works on any android OS level should work on all levels. The inconstancy of SimpleDateFormat is most likely due to different locale on different devices. to fix that use one locale instead of using the device's default Locale.

new SimpleDateFormat(dataFormat,Locale.US);
于 2013-03-21T16:56:30.663 回答
1

不了解android,但在java中你可以通过以下方式获取系统属性:java.lang.System.getProperties()

于 2013-03-21T16:43:48.020 回答
0

I'm having similar issue on a Samsung Galaxy 7 tablet.

"EDT" is not in the list returned by TimeZone.getAvailableIDs(), so a SimpleDateFormat using "z" does not work.

I'm going to make a hash table of TZ abbreviations and convert the codes to += offset.

Unbelievable, really...

于 2013-06-25T17:30:20.570 回答