I'm parsing this date format from XML:=> "2011-12-06T07:41:14.016+00:00", and I'm getting this error:
I'm certain it's the formatting statement I'm using, but I can't figure out what it SHOULD be...
Here's the statement I'm using:
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss.SSSZ:ss");
I get how to create a format for this part: "2011-12-06T07:41:14....", it's this other part :=> ".016+00:00" that's throwing me for a loop.
I've looked for answers here already: Android SimpleDateFormat Page, and here Oracle SimpleDateFormat Page, but I fear I'm missing something fundamental....
Do you have any suggestions on a proper format statement for that particular date format, or pertinent resources to peruse?
Big Thanks in advance!
The error java.text.ParseException: Unparseable date usually occurs while using the SimpleDateFormat class in Java. This class is used to format the date in Java. Most of the time, the error java.text.ParseException: Unparseable date occurs when we try to convert the string date into another desired date format.
I believe that SimpleDateFormat will not parse timezones with a colon in them (-08:00). It should be able to parse the date 2011-10-06T12:00:00-0800. Some simple string manipulation should help you get rid of the colon. Show activity on this post. You first need to format the value in "2011-10-06T12: 00: 00-08: 00".
The timezone should be GMT-08:00 or -0800 (as Madcore Tom said). See Java docs. Show activity on this post. I believe that SimpleDateFormat will not parse timezones with a colon in them (-08:00).
Now, in your formatDate () method, simple try all your known format and trap the Exception, then if still did not have a date, just use Date d = javax.xml.bind.DatatypeConverter.parseDateTime ("2013-06-28T00:00:00+00:00").getTime (); if (d == null) try { SimpleDateFormater ...
The "Z" pattern matches +0000 and not +00:00 so if you remove the last ":" before you parse then it will work.
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss.SSSZ");
try {
Date myDate = sdf.parse( "2011-12-06T07:41:14.016+00:00".replaceAll( "([0-9\\-T]+:[0-9]{2}:[0-9.+]+):([0-9]{2})", "$1$2" ) );
System.out.println( myDate );
} catch (ParseException e) {
e.printStackTrace();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With