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 Current date and time Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Current date and time" Watch "Current date and time" New topic
Author

Current date and time

V.R. Sundar
Greenhorn

Joined: May 27, 2003
Posts: 10
hi,
I have a log class for logging all error messages/output. I would like to modify it to add a timestamp to the message and also create the log file based on the current date. How do i get the current date and time. I looked some classes including Calender but could not find an easy way to do this (or atleast one that i understood easily . Does anyone have any suggestions on how to do this?
thanks
sundar
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

Well, if you create a Date object with no constructor arguments, it represents "right now". The Date.toString() method produces a lovely rendering of the Date. So...

should give you just what you want, something like "Tue Jul 29 17:40:37 PDT 2003".
[ July 29, 2003: Message edited by: Ernest Friedman-Hill ]

[Jess in Action][AskingGoodQuestions]
qingwu wang
Ranch Hand

Joined: Feb 19, 2003
Posts: 147
System.out.println(new Date()+": "+msg);


Thanks...qingwu<br />When I open my eyes,I see your pretty face.
V.R. Sundar
Greenhorn

Joined: May 27, 2003
Posts: 10
Originally posted by qingwu wang:

Originally posted by Ernest Friedman-Hill:

Ernest & qingwu,
Thanks for the info. I used the Date class and it works fine.
sundar
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Current date and time