1

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?

Kimi
  • 6,239
  • 5
  • 32
  • 49
  • I read [the documentation](http://download.oracle.com/javase/1.4.2/docs/api/java/text/SimpleDateFormat.html#timezone), but couldn't get it parsed. – Kimi Jul 15 '11 at 09:49
  • 3
    From reading the documentation, it looks as if GMT+300 isn't valid, but GMT+3:00 would be. Is there any way you could manipulate the timezone portion of your input string first so that it's actually valid? – Anthony Grist Jul 15 '11 at 09:54
  • GMT+300 is not valid format, +0300 is – Vlad Jul 15 '11 at 09:59
  • [Joda Time](http://joda-time.sourceforge.net/) can deal with this. – wjans Jul 15 '11 at 10:01
  • Well, the problem is that the String is coming directly from our UI framework's built-in form component DateItem ([SmartGWT](http://www.smartclient.com/smartgwt/javadoc/com/smartgwt/client/widgets/form/fields/DateItem.html)). Maybe I'll inform the developers and wait for it to get fixed. – Kimi Jul 15 '11 at 10:05
  • You could even work around the 'GMT' part declaring it as a literal, but the +300 is an error (that's like turning 25 times around the globe, isn't it?) Either it has to become +0300 or +3:00 – maasg Jul 16 '11 at 08:21
  • @anthonyg Make your comment an answer and I'll accept it. – Kimi Jul 16 '11 at 13:46

1 Answers1

3

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

Kimi
  • 6,239
  • 5
  • 32
  • 49