使用SimpleDateFormat解析使用GMT时区到日期的字符串 [英] Parsing a String with a GMT timezone to Date using SimpleDateFormat
本文介绍了使用SimpleDateFormat解析使用GMT时区到日期的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我从以下格式的输入字符串中解析日期有问题:
I'm having problem parsing the Date from an input string that is of the following format:
String input = "Fri Jul 15 12:00:00 GMT+300 2011";
String dateFormat = "EEE MMM d HH:mm:ss z yyyy";
Date date = new SimpleDateFormat(dateFormat).parse(input);
抛出异常:
java.text.ParseException: Unparseable date: "Fri Jul 15 12:00:00 GMT+300 2011"
at java.text.DateFormat.parse(DateFormat.java:337)
我打赌它与GMT字符串有关。我想我已经尝试过 z
, zzz
, zZ
和 zzzZ
。
任何想法?输入 GMT + 300
甚至是标准的有效输入格式?
I bet it has got something to do with the GMT string. I think I've tried it with z
, zzz
, zZ
, and zzzZ
.
Any thoughts? Is the input GMT+300
even a standard, valid input format?
推荐答案
The problem was that GMT+300
isn't valid GMT string according to the Java Timezone specification.
/ strong>:操作输入字符串的时区部分。 GMT + 300
==> GMT + 3:00
这篇关于使用SimpleDateFormat解析使用GMT时区到日期的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文