# a constructor to convert seconds to hours, min & seconds

• 04-05-2010, 11:58 AM
senca
a constructor to convert seconds to hours, min & seconds
hey everyone,

I am trying to figure out how to make the following: converting a value of seconds and convert it to the amount of hours,minutes and seconds it is.
For instance 7200 sec would give me 2 hours, 0 minutes and 0 seconds.
I know it is something with % but I can't figure out how to do it.
The code I started out with looks like this:

public Time(int totSeconds){
something like ==> int out = totSeconds % 3600; this gives me the rest but not the amount of hours :s
...

if anyone can help me, thanks in advance :)
• 04-05-2010, 12:39 PM
JosAH
This is simpler than math 101: there are 3600 seconds in an hour, you have 7200 seconds, so you have 7200/3600 == 2 hours.

kind regards,

Jos
• 04-05-2010, 12:56 PM
senca
but how does it work with minutes and seonds? for example 7350 seconds?
if you devide then there is a rest somewhere but where?
• 04-05-2010, 01:08 PM
JosAH
Quote:

Originally Posted by senca
but how does it work with minutes and seonds? for example 7350 seconds?
if you devide then there is a rest somewhere but where?

7350/3600 == 2
7350%3600 == 150

kind regards,

Jos