Algorithm of Java Date getTime

995 Views Asked by At

How does java.util.Date.getTime method convert a given date & time into long number?

Java API documents say that - "Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this Date object."

Appreciate any help.

2

There are 2 best solutions below

0
On

Check out the Date.java source code.

You'll see that in the simplest case, the Date object stores the number of milliseconds since 1970, rather than the date/time etc.

3
On

Actually, despite the apparently unambiguous definition in the Java API doc, it is interesting to note that the number of milliseconds reported is not the actual number of physical milliseconds, or seconds for that matter, that have elapsed since January 1st 1970 00:00:00 GMT. It is really the number of physical seconds plus the number of leap seconds that have been artificially inserted.