Search code examples
javajava.util.date

Java Date start epoch


The java.util.Date class is based on the number of seconds since 1 January 1970 00:00 GMT. So why does this code

System.out.println(new Date(0));

print Thu Jan 01 01:00:00 GMT 1970? My local time zone is GMT, so I expected it to print 00:00:00 GMT.


Solution

  • There is an interesting reason for this. Refer (BST Offset bug report) . It says, "and the experiment with British Standard Time from 1968 to 1972, by which the time was advanced by one hour from GMT throughout the year." And further: “The local time produced by Date.toString() is historically correct, except for the time zone abbreviation. It should be "BST" (British Standard Time for this case), but it's a known limitation of the current TimeZone implementation.”