Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Date(long date) constructor

 
Tayitu Betule
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
EST is 5 hours behind GMT, so the two dates are identical.
 
Pat Farrell
Rancher
Posts: 4678
7
Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you both. I forgot about the time difference.
 
Bert Bates
author
Sheriff
Posts: 8905
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
BTW, this could be considered a valid SCJP question.
 
Tayitu Betule
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic