Home > database >  Java ParseException Unparseable date when date string is UTC 13:00 timezone
Java ParseException Unparseable date when date string is UTC 13:00 timezone

Time:04-05

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?

CodePudding user response:

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" )
  •  Tags:  
  • java
  • Related