DodgyCodeException
DodgyCodeException

Reputation: 6133

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.

Upvotes: 3

Views: 3440

Answers (3)

CGS
CGS

Reputation: 2872

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.”

Upvotes: 5

Robo Mop
Robo Mop

Reputation: 3553

This link might help. I'm quite a novice at the Date class, but I figured this could help somehow.

Upvotes: 1

Austin Schaefer
Austin Schaefer

Reputation: 696

Unix Epoch Time is a system of time describing how much time has elapsed since January 1st, 1970.

Therefore, when you create a new java.util.Date object with 0 milliseconds elapsed, it will return January 1st, 1970.

What you are looking for is here.

Upvotes: -1

Related Questions