File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Date and Time Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Date and Time" Watch "Date and Time" New topic
Author

Date and Time

Peter Phung
Ranch Hand

Joined: Dec 06, 2001
Posts: 138
Just a simple question
Can anyone tell me how to get the date and time of the system?


Pete<br />"Reality is an illusion <br />brought on by a lack of <br />drink, drugs and smut"
Rene Liebmann
Ranch Hand

Joined: May 02, 2002
Posts: 196
Hi Pete,
when you initialize a Date with an empty constructor (Date date = new Date();) then it is initialized with the current Date and Time on your computer. Is this what you mean?
Rene
[ July 10, 2002: Message edited by: Rene Liebmann ]
Peter Phung
Ranch Hand

Joined: Dec 06, 2001
Posts: 138
Yeah, sort of. I need to enter the date and time into a database. So i need to be able to return the date and time in a specific format i.e. if the date and time was July 10th 2002 9:45 i would need the:
date : 2002-07-10
time : 09:45:00
the api isn't very clear on how to achieve this. Can you help?
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

Try this link:
http://java.sun.com/j2se/1.3/docs/api/java/text/SimpleDateFormat.html
/Rene


Regards, Rene Larsen
Dropbox Invite
Rene Liebmann
Ranch Hand

Joined: May 02, 2002
Posts: 196
Yes, SimpleDateFormat could be one solution. Another Possibility is the Calendar (GregorianCalendar). If you create a new GregorianCalendar then it already is initialized with the current time. Then the Calendar object has lots of methods to get what you want. Therefore the API has a good example.
Good luck
Mahesh Mamani
Ranch Hand

Joined: Jun 25, 2001
Posts: 110
Hi,
When using the Calendar class, do take care of this functionality regd. month...
Use this URL for more info

MSM
Peter Phung
Ranch Hand

Joined: Dec 06, 2001
Posts: 138
I used SimpleDateFormat because that's all i needed.
Thanks to both Rene's, your help was much appreciated.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Date and Time