Hello,

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?

## All 3 Replies

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

or

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?

DOnt worry - got it, thanks :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.