This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes How to get the current time in java? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "How to get the current time in java?" Watch "How to get the current time in java?" New topic
Author

How to get the current time in java?

Chris Ben
Ranch Hand

Joined: Jan 15, 2001
Posts: 135
Hi all,
I want to create a unique key using current time (up to milisec if possible), but I forget the proper class and methods that I should use. Could someone please tell me how to do that?
Thanks a lot
Chris
San Su
Ranch Hand

Joined: Jul 06, 2001
Posts: 313

Calendar.getInstance() returns Calendar object initialized
with the current time.
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

I think you're looking for :



Which returns a long signifying the number of milliseonds that have elapsed since midnight Jan. 1, 1970. Cast the long to a String, and you have a unique key and/or timestamp.

HTH,
-Nate


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Chris Ben
Ranch Hand

Joined: Jan 15, 2001
Posts: 135
Hi Sankar and Nathan,
Thank you for your help. I got it.
Chris
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: How to get the current time in java?
 
Similar Threads
system time and day
datetime default in XML
New to Java
how to get a current date and time in java?
javascript function to return a value