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

1. Member
Join Date
Feb 2010
Posts
36
Rep Power
0

## 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 :)

2. 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

3. Member
Join Date
Feb 2010
Posts
36
Rep Power
0
but how does it work with minutes and seonds? for example 7350 seconds?
if you devide then there is a rest somewhere but where?

4. 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

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•