Home > Java > The missing hour

The missing hour

Yesterday I wrote a validation program for files with measurements. It reported 2012-03-25 02:00 as an invalid date given the date format yyyy-MM-dd HH:mm. Strange, what could be wrong?

Eventually I found it. This blows up:


DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm");
df.setLenient(false);
df.parse("2012-03-25 02:00");

However, change the time zone to UTC and it works:


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

Daylight savings (again). The specified hour does not exist with the default time zone (Europe/Stockholm).

Advertisements
Categories: Java
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: