Parsing a GMT timezone string by date using SimpleDateFormat

I am having a problem parsing a date from an input string, which has 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 am sure this is due to the GMT string. I think I tried it with the z, zzz, zZand zzzZ. Any suggestions? Is the input a GMT+300standard, valid input format?

+1
source share
1 answer

The problem was that GMT+300it is not a valid GMT string according to the Java Timezone specification .

: . GMT+300 == > GMT+3:00

+2

Source: https://habr.com/ru/post/1569547/


All Articles