Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How come new Date(0L) doesn't return zero date

Tags:

java

datetime

Date date = new Date(0L);

Shouldn't it give me a zero date? Like 00/00/0000? Gives me Wed Dec 31 19:00:00 EST 1969

like image 212
Alexander Sabot Avatar asked Jun 22 '11 16:06

Alexander Sabot


3 Answers

Per the javadocs, this constructor on Date uses an offset from baseline time:

Allocates a Date object and initializes it to represent the specified number of milliseconds since the standard base time known as "the epoch", namely January 1, 1970, 00:00:00 GMT.

Presumably you are on EST, hence the result.

As an aside, I would not expect the result you noted to be produced by any conceivable Date manipulation, since that's not even a valid date (month and day = 0).

like image 177
Steve Townsend Avatar answered Oct 13 '22 21:10

Steve Townsend


From the Java API:

Date(long date): Allocates a Date object and initializes it to represent the specified number of milliseconds since the standard base time known as "the epoch", namely January 1, 1970, 00:00:00 GMT.

See: http://download.oracle.com/javase/1.4.2/docs/api/java/util/Date.html

like image 39
FishBasketGordo Avatar answered Oct 13 '22 22:10

FishBasketGordo


The time is milliseconds since the epoch.

The epoch is 1/1/1970 GMT.

like image 20
Reverend Gonzo Avatar answered Oct 13 '22 21:10

Reverend Gonzo