This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Java in General and the fly likes Date(long date) constructor Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply 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: 35239
    
    7
EST is 5 hours behind GMT, so the two dates are identical.


Android appsImageJ pluginsJava web charts
Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4422
    
    2

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: 8712
BTW, this could be considered a valid SCJP question.


Eliminate fossil fuel subsidies. (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
 
Similar Threads
Simple Date conversion problem
reading time
Calendar Class
Unparseable date exception....!!!!
Convert String value to Date Object