Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to get the current time in java?

 
Chris Ben
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 313
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Calendar.getInstance() returns Calendar object initialized
with the current time.
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Chris Ben
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sankar and Nathan,
Thank you for your help. I got it.
Chris
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic