如何解析具有单个数字偏移量的时区? “ 1969年12月31日星期三00:00:00 GMT-8” [英] How to Parse Timezone with Single Digit Offset? "Wed Dec 31 00:00:00 GMT-8 1969"
问题描述
我有这个日期:
"Wed Dec 31 00:00:00 GMT-8 1969"
但无法使用此SimpleDateFormat进行解析:
But it cannot be parsed with this SimpleDateFormat:
new SimpleDateFormat("EEE MMM dd hh:mm:ss zzz yyyy");
如何在 -8
中指定格式字符串?在阅读SDF文档之后,我尝试了 Z
和 X
,但无济于事。我应该使用什么?
How do I specify the -8
in the format string? I have tried Z
and X
after reading the SDF docs, but to no avail. What should I use?
推荐答案
使用 -8
非ISO标准格式。
The use of -8
is in a non ISO standard format.
类似于 -0800
或 -08:00
是预期的。这是因为时间偏移可能包括半小时。
Something like -0800
or -08:00
is expected. This is because the time offset can include half hours.
您应该先对字符串进行预处理转换,然后再将其传递给SimpleDateFormat并将其更改为星期三12月31日00:00:00 GMT -0800 1969
并使用:
You should run a preprocessing conversion on the string before passing it to the SimpleDateFormat and change it to "Wed Dec 31 00:00:00 GMT-0800 1969"
and use:
new SimpleDateFormat( EEM MMM dd hh:mm: ss Z yyyy);
如果您想使其更简单,只需创建一个方法来替换 -8
与 America / Los_Angeles
并使用 ZZZ
。
If you want to make it simpler just create a method to replace the -8
with America/Los_Angeles
and use ZZZ
.
这篇关于如何解析具有单个数字偏移量的时区? “ 1969年12月31日星期三00:00:00 GMT-8”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!