Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java date format pattern

Tags:

java

I have problems finding a java date pattern that correctly reads this date from a string:

2012-01-17T11:53:40+00:00

If the timezone would be standard (+0000), this pattern would work:

yyyy-MM-dd'T'HH:mm:ssZ

but this is not the case. The small z doesn't match either.

like image 816
mana Avatar asked Jan 18 '12 13:01

mana


2 Answers

Replace the last colon by an empty string, and then parse. Simplest solutions are sometimes the best ones.

like image 131
JB Nizet Avatar answered Oct 11 '22 02:10

JB Nizet


In Java 7, you can use the letter X to represent an ISO 8601 time zone.

SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX");
like image 31
dogbane Avatar answered Oct 11 '22 02:10

dogbane