I have the following string in Java:
2011-12-21T20:27:32-08:00
Can any one tell me how do I store this string by converting it to date?
I need to store it in a MySQL column declared as TimeStamp.
I’ve tried the following but it does not work:
Date date = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssz").parse("2011-12-21T20:27:32-08:00");
It gives below error:
Exception in thread "main" java.text.ParseException: Unparseable date: "2011-12-21T20:27:32-08:00" –
Any help is much appreciated.
According to the documentation,
zexpects timezone indicators in a different format than the one in your string, but you can useXinstead, which supports them. So (change is at the end of the format string):From the docs:
Daniel Kaplan points out in the comments that
Xseems to be new. You might need to pre-process the string a bit to remove the colon and useZ(capital, notz; the second in the list above) instead, depending on your environment.