This week's book giveaway is in the JavaScript forum.
We're giving away four copies of JavaScript Promises Essentials and have Rami Sarieddine 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 | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
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://aspose.com/file-tools
 
subject: How to get the current time in java?