Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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);

An exception is thrown:

java.text.ParseException: Unparseable date: "Fri Jul 15 12:00:00 GMT+300 2011"
    at java.text.DateFormat.parse(DateFormat.java:337)

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
651 views
Welcome To Ask or Share your Answers For Others

1 Answer

The problem was that GMT+300 isn't valid GMT string according to the Java Timezone specification.

Solution: Manipulating the timezone portion of input string. GMT+300 ==> GMT+3:00


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...