Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

milliseconds

 
Jelle Paelman
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Is there anyway to get the exact milliseconds of the time.
The result i got with the code below is mostly the same and sometimes 10 milliseconds more, but never just 1 millisecond(which i need to make a unique code and not lose to much time)
Apparently it never changes the milliseconds but only every ten milliseconds.
for (int i = 0; i <50; i++)
{
try { Thread.sleep(1); }
catch (InterruptedException e) {}
System.out.println(System.currentTimeMillis()) ;
}
Hope someone can help me,
Jelle
 
Matt Senecal
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is some code from a CORBA app I wrote that returns the date with milliseconds. If you create a calendar, you should be able to pull the current time out, like so:
 
Jelle Paelman
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Still don't work, i still need a 10 millisecond delay(Thread.sleep(10)) to get a unique code.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic