4

I am getting an exception when parsing date 20160327020727 with format yyyyMMddhhmmss. Note that the lenient is set to false.

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

It is parsing other dates with the same format and it is working as expected. Why is this happening?

Amer Hukic
  • 1,494
  • 1
  • 19
  • 29

3 Answers3

7

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

You go from 1:59 to 3:00

Akah
  • 1,890
  • 20
  • 28
2

You are getting an error because that time does not exist in your default time zone.

Try setting the timezone to UTC by doing df.setTimeZone(TimeZone.getTimeZone("UTC"));

In CET on the last Sunday of march it changes to summertime -> No 2AM on that day.

DevNico
  • 138
  • 1
  • 12
-1

Change it to "yyyyMMdd HHmmss", so you can parse it easily.

Bugs
  • 4,491
  • 9
  • 32
  • 41