File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes milliseconds Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "milliseconds" Watch "milliseconds" New topic


Jelle Paelman

Joined: Feb 08, 2001
Posts: 2
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,
Matt Senecal
Ranch Hand

Joined: Dec 01, 2000
Posts: 255
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:

There's nothing more dangerous than a resourceful idiot. ---Dilbert
Jelle Paelman

Joined: Feb 08, 2001
Posts: 2
Still don't work, i still need a 10 millisecond delay(Thread.sleep(10)) to get a unique code.
I agree. Here's the link:
subject: milliseconds
It's not a secret anymore!