SimpleDateFormat with template yyyyMMddhhmmss, unable to parse date "20160327020727"

I get an exception when parsing a date 20160327020727with a format yyyyMMddhhmmss. Note that the softness parameter is set to false.

    SimpleDateFormat df = new SimpleDateFormat("yyyyMMddhhmmss");
    df.setLenient(false);
    try {
        Date dt = df.parse("20160327020727");
    } catch (ParseException e) {
        e.printStackTrace();
    }

It processes other dates in the same format and works as expected. Why is this happening?

+4
source share
3 answers

CET changes to summer time on the last Sunday of March, so there is no 2AM on this day.

You go from 1:59 to 3:00

+7
source

You get an error because this time does not exist in your default time zone.

UTC, df.setTimeZone(TimeZone.getTimeZone("UTC"));

CET → No 2AM .

+2

Change it to "yyyyMMdd HHmmss"so you can easily disassemble it.

-1
source

Source: https://habr.com/ru/post/1651806/


All Articles