aspose file tools*
The moose likes Java in General and the fly likes Date(long date) constructor Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Date(long date) constructor" Watch "Date(long date) constructor" New topic

Date(long date) constructor

Tayitu Betule
Ranch Hand

Joined: Dec 18, 2009
Posts: 39
The following program prints "Wed Dec 31 19:00:01 EST 1969". Why?

import java.util.*;

public class dateTest{

public static void main(String args[]){

Date dt=new Date(1000);

According to JS2E API - 'It should 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'.

Thank you all for your help.
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42925
EST is 5 hours behind GMT, so the two dates are identical.
Pat Farrell

Joined: Aug 11, 2007
Posts: 4659

Tayitu Betule wrote: Date dt=new Date(1000);

This is 1000 miliseconds since the beginning of Java time, i.e. one second after zero time.
Tayitu Betule
Ranch Hand

Joined: Dec 18, 2009
Posts: 39
Thank you both. I forgot about the time difference.
Bert Bates

Joined: Oct 14, 2002
Posts: 8883
BTW, this could be considered a valid SCJP question.

Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
Tayitu Betule
Ranch Hand

Joined: Dec 18, 2009
Posts: 39
At first, I did post it at SCJP forum... but couldn't find it there when I try to see if anybody has replied. I did a search and found it in this forum. Anyways, thanks for clearing my doubts.
I agree. Here's the link:
subject: Date(long date) constructor