I have looked through previous questions, but none had the answer I was looking for. How do I convert milliseconds from a StopWatch method to Minutes and Seconds? I have:
watch.start();
to start the stopwatch and
watch.stop();
to stop the watch. I later have
watch.getTime();
which returns Milliseconds. I want it to return in Seconds and Minutes. How do I go about doing so? I'm looking for a way to do it without multiplying/dividing by 1000 but rather a method that will make the whole computation more readable and less error-prone.
I would suggest using TimeUnit
. You can use it like this:
long minutes = TimeUnit.MILLISECONDS.toMinutes(millis);
long seconds = TimeUnit.MILLISECONDS.toSeconds(millis);