Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SimpleDateFormat and 2013-01-17T00:00:00-06:00

Tags:

java

What would be the correct format to use in SimpleDateFormat to parse incoming dates that look like this: "2013-01-17T00:00:00-06:00"?

like image 226
Rocky Pulley Avatar asked Dec 01 '25 04:12

Rocky Pulley


2 Answers

This format should work:

"yyyy-MM-dd'T'HH:mm:ssXXX"
like image 89
Henry Avatar answered Dec 02 '25 17:12

Henry


You have to trim the last colon to align with java's zone info format of "-0600".

Try this:

String str = "2013-01-17T00:00:00-06:00";
new SimpleDataFormat("yyyy-MM-dd'T'hh:mm:ssZ").parse(str.replaceAll(":(..)$", "$1"));
like image 21
Bohemian Avatar answered Dec 02 '25 17:12

Bohemian