Correct Way of Calculating Elapsed Time in Java

You may also like...

Subscribe
Notify of
guest
2 Comments
Oldest
Newest
Inline Feedbacks
View all comments
Nathaniel M
Nathaniel M
October 7, 2016 23:53

public String toMinuteSeconds(){
return String.format(“%d min, %d sec”, time(TimeUnit.MINUTES),
time(TimeUnit.SECONDS) – (time(TimeUnit.MINUTES) * 60));
}

The original didn’t have the ” * 60″, so the seconds didn’t subtract correctly.

James Caldwell
James Caldwell
April 19, 2018 01:41
Reply to  Nathaniel M

Also in the Basic Time Elapsed code there is TimeUnit.NANOSECONDS.toHours(difference) which should be changed to TimeUnit.NANOSECONDS.toMinutes(difference)

2
0
Would love your thoughts, please comment.x
()
x