I have a countdown timer. The countdown timer counts down in miliseconds. I have worked out hours by using the sum:

(((millisUntilFinished / 1000) / 60) / 60)

Now minutes, I did this today and I seriously can not see how minutes works, but it does, here is what I have done for minutes...

long minsTotal = hoursS * 60;
(((millisUntilFinished / 1000) / 60) - minsTotal)

Now when I typed that in to a caluculator it awlays equated to 0... But somehow it works....

Now the seconds is where i'm stuck. To work out the seconds I have used:

long secs = (millisUntilFinished / 1000);

which works out the total seconds. However I want the highest number for it to display as 60. How could I stop if from going over 60, but still working properly?

4 Years
Discussion Span
Last Post by aVar++

Check out the % (remainder) operator - gives you the remainder after dividing, eg
27/6 = 4
27%6 = 3
ie 27 is 6*4 + 3


secs = 140;
secs/60 = 2 (minutes)
secs%60 = 20 (seconds)


Ok, so how would I use that for converting milliseconds to seconds? and making sure it stays under 60?

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.