File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/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


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Date(long date) constructor" Watch "Date(long date) constructor" New topic
Author

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);
System.out.print(dt);
}
}

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
Marshal

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


Ping & DNS - my free Android networking tools app
Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4659
    
    5

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
author
Sheriff

Joined: Oct 14, 2002
Posts: 8875
    
    5
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: http://aspose.com/file-tools
 
subject: Date(long date) constructor