Home arrow static arrow Java Programming [Archive] - how do i get the current time and date?
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - how do i get the current time and date?
This topic has 4 replies on 1 page.

Posts:64
Registered: 12/23/03
how do i get the current time and date?  
Aug 2, 2004 3:30 AM



 
how do i get the current time and date?
 

Posts:16
Registered: 7/31/04
Re: how do i get the current time and date?  
Aug 2, 2004 3:52 AM (reply 1 of 4)



 
Date date = new Date();
System.out.println(date);

i do believe
 

Posts:16
Registered: 7/31/04
Re: how do i get the current time and date?  
Aug 2, 2004 3:54 AM (reply 2 of 4)



 
oh yea you have to import java.util
 

Posts:16
Registered: 7/31/04
Re: how do i get the current time and date?  
Aug 2, 2004 3:57 AM (reply 3 of 4)



 
err sorry for yet another post on the same thread.... that statement wont apply Daylight Savings Time im not sure if there are premade methods in the API for this or not... you may have to do it manually by detecting for the day/month with date format and applying DST / removing DST based on the date.
 

Posts:5,904
Registered: 04/03/99
Re: how do i get the current time and date?  
Aug 2, 2004 3:58 AM (reply 4 of 4)



 

ZionStorm's suggestion is certainly the easiest way to do this. However, a lot of the Date class is now deprecated, so you should probably also familiarise yourself with the Calendar classes.

Calendar knows about internationalization (i18n) and localization (l10n). It knows about leap years (in the Gregorian Calendar) and other such quirks. It allows you to do basic date manipulation in a way that allows you to be confident that things will behave as the user expects.

That said, for very simple purposes (logging and the like) Date is much easier to use !

Dave.
 
This topic has 4 replies on 1 page.