Skip to content
Advertisement

In Java, what is the fastest way to get the system time?

I’m developing a system that often use the system time because the Delayed interface.

What is fastet way to get the time from system?

Currently I’m using Calendar.getInstance().getTimeInMillis() every time I need to get the time, but I don’t know if there is a faster way.

Advertisement

Answer

System.currentTimeMillis()
“Returns the current time in milliseconds”.
Use this to get the actual system time.

System.nanoTime().
“The value returned represents nanoseconds since some fixed but arbitrary origin time”
Use this is you’re measuring time lapses / events.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement