Measuring Time 🕰
Many applications require a very precise time measurement. For this purpose, Java provides static methods in System class. 🔆
1️⃣ - currentTimeMillis(): Returns current time in MilliSeconds since Epoch Time, in Long.
view sourceprint?
2️⃣ - nanoTime(): Returns the current value of the most precise available system timer, in NanoSeconds, in long.
nanoTime() is meant for measuring relative time interval instead of providing absolute timing.
#java #time
@ProgrammingTip
Many applications require a very precise time measurement. For this purpose, Java provides static methods in System class. 🔆
1️⃣ - currentTimeMillis(): Returns current time in MilliSeconds since Epoch Time, in Long.
view sourceprint?
long startTime = System.currentTimeMillis();
long estimatedTime = System.currentTimeMillis() - startTime;
2️⃣ - nanoTime(): Returns the current value of the most precise available system timer, in NanoSeconds, in long.
nanoTime() is meant for measuring relative time interval instead of providing absolute timing.
long startTime = System.nanoTime();
long estimatedTime = System.nanoTime() - startTime;
#java #time
@ProgrammingTip