Why is this code throwing exception of unparseable date?
SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'.000Z'");
f.setLenient(false);
String dateStr = "2012-03-11T02:46:01.000Z";
f.parse(dateStr);
It works fine when lenient is true. It strangely works for input date ‘2012-03-01T02:46:01.000Z‘ even with lenient as false.
Default timezone being used : PST
Because that time does not exist in your default time zone—it was daylight savings time change day, and time jumped from 2:00 a.m. to 3:00 a.m., so there was no 2:46 that morning. 😛
Since you’re parsing UTC, set the
SimpleDateFormatinstance time zone to UTC like so:and your problem will go away.