Opaque date with time zone separated by a colon

I am trying to parse this line

2014-04-04T14: 28: 38 + 02: 00

It must be an ISO 8601 format. But I cannot parse it to the correct date. I tried the following:

String example = "2014-04-04T14:28:38+02:00" public final static SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssz") Date tempDate = df.parse(example) 

But I always get the message "unprepared date", I can not change the example, because it is a value from the web service.

Could there be a problem with "+02: 00" instead of "+0200"?

thanks a lot

+1
source share
2 answers

Starting with Java7, you can use the following format to handle +02: 00:

 "yyyy-MM-dd'T'hh:mm:ssXXX" 

This can be seen in the SimpleDateFormat documentation.

+1
source

The ISO8601 date format can be most easily analyzed using Joda Time , which can be used as a library.

It seems that the Joda Time form got into Java 8 as JSR310 , but I did not work with it.

0
source

All Articles