Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Java ParseException Unparseable date when date string is UTC+13:00 timezone

I am getting weird error which I can’t get around easily.
This is my code

DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.[S][SS][SSS][SSSS][SSSSS][SSSSSS][SSSSSSS][SSSSSSSS][SSSSSSSSS]X");
df.setTimeZone(TimeZone.getDefault());
Date issued = df.parse(this.dateAndTimeOfIssue);

I am getting exception
java.text.ParseException: Unparseable date: "2018-02-13T00:00:51.045+13:00"

Does anyone knows what is causing error?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You are using terrible date-time classes that were years ago supplanted by the modern java.time classes defined in JSR 310. Avoid Date/Calendar.

For a date with time of day as seen with a particular offset, use OffsetDateTime class.

Your input text complies with the standard ISO 8601 format used by default in the java.time classes. So no need to specify a formatting pattern.

OffsetDateTime.parse( "2018-02-13T00:00:51.045+13:00" )
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading