javasimpledateformat

Java SimpleDateFormat gives different time zone for different day


I had a strange behaviour when parsing dates. Given

DateFormat sdf= new SimpleDateFormat("dd/MM/yyyy");

sdf.parse("25/10/2014") returns 25 Oct 2014 00:00:00 BST

while

sdf.parse("27/10/2014") returns 27 Oct 2014 00:00:00 GMT

I figured out that's because of the Daylight Time change, but surely I would expect the same time zone to be returned by the same parser. Or am I wrong?


Solution

  • Per the Wikipedia article on British Summer Time

    During British Summer Time (BST), civil time in the United Kingdom is advanced one hour forward of Greenwich Mean Time (GMT), so that evenings have more daylight and mornings have less

    BST begins at 01:00 GMT on the last Sunday of March and ends at 01:00 GMT (02:00 BST) on the last Sunday of October.

    The last Sunday of October 2014 was the 26th. So, the TimeZone changed from British Summer Time to GMT as observed in the UK.

    The default TimeZone is your system TimeZone, so when that changes your parser will too.