-3

When we convert the date from yyyy-MM-dd'T'HH:mm:ssXXX to YYMMDD date is invalid.

Say.. If the date is 2019-02-27T12:52:58.249Z then the converted date is generated as "190258"

Chitra
  • 13
  • 1
  • 7
  • Target format must be yyyyMMdd – Jens Feb 28 '19 at 05:43
  • Thanks a lot it worked fine for us :-) – Chitra Feb 28 '19 at 06:37
  • I recommend you don’t use `SimpleDateFormat` and `Date`. Those classes are poorly designed and long outdated, the former in particular notoriously troublesome. Instead use `OffsetDateTime` and `DateTimeFormatter`, both from [java.time, the modern Java date and time API](https://docs.oracle.com/javase/tutorial/datetime/). – Ole V.V. Feb 28 '19 at 09:25

1 Answers1

1

The issue is because of 'D' in the input format.

D represents Day of the year - so when we give 2019-02-27 it adds the 31 days in Jan and 27 days in Feb so the day is counted as '58'.

After changing the format to 'd' it works fine.

Similarly, 'Y' represents week of the year - so we have replaced that to 'y' which represents year

Chitra
  • 13
  • 1
  • 7