Home arrow static arrow Java Programming [Archive] - Date abd getTime
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - Date abd getTime
This topic has 4 replies on 1 page.

Posts:64
Registered: 12/23/03
Date abd getTime  
Aug 8, 2004 1:25 AM



 
i am doing :
[CODE]
Date startTime = new Date();
System.out.println(startTime.getTime());
[/CODE]
and if i use the getTime not immediatly but 10 seconds after i have declared startTime i get the time of the creaton ! why is that?
how can i get the real curent time in milliseconds?
thnaks in advance
peleg
 

Posts:18,384
Registered: 21.03.00
Re: Date abd getTime  
Aug 8, 2004 1:34 AM (reply 1 of 4)



 
System.currentTimeMillis();

/Kaj
 

Posts:64
Registered: 12/23/03
Re: Date abd getTime  
Aug 8, 2004 5:14 AM (reply 2 of 4)



 
first thanks!
secind why is the Date.getTime()!=System.currentTimeMillis();
 

Posts:18,384
Registered: 21.03.00
Re: Date abd getTime  
Aug 8, 2004 5:20 AM (reply 3 of 4)



 
Hi,

Dates are more or less like snapshots. They represents a date in time, and not the current time. But calling new Date() is the same as calling new Date(System.currentTimeMillis()).

E.g a Date object is normally used if you what to represent a date. Like 25th of Jan 2004.

/Kaj
 

Posts:37,103
Registered: 3/30/99
Re: Date abd getTime  
Aug 8, 2004 11:39 AM (reply 4 of 4)



 
first thanks!
secind why is the
Date.getTime()!=System.currentTimeMillis();

Date reperesents a point in time. Which point is set when you create it, or when you set it with setTime(). Calling getTime() just returns a particular view of whatever instant in time that Date happens to represent.
 
This topic has 4 replies on 1 page.