### Thread: Convert seconds to minutes:seconds

1. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Aug 2006
Posts
13
Rep Power
0

#### Convert seconds to minutes:seconds

Hi. I think i'm being a complete mathematical idiot, but how do you convert seconds (eg. 70) to minutes:seconds (1:10)? I'm drawing a complete blank!!! I've thought of dividing by 60 but what do you do with the remainder??

2. 70 modulo 60, which in javascript is written as
Code:
`70 % 60`
3. No Profile Picture
Contributing User
Devshed Novice (500 - 999 posts)

Join Date
Sep 2003
Posts
507
Rep Power
22
Originally Posted by marnixR
70 modulo 60, which in javascript is written as
Code:
`70 % 60`
To take a step further you could try this (i have not fully tested this):

javascript Code:
```String.prototype.pad = function(l, s){
return (l -= this.length) > 0
? (s = new Array(Math.ceil(l / s.length) + 1).join(s)).substr(0, s.length) + this + s.substr(0, l - s.length)
: this;
};

var seconds = 121;
document.write( Math.floor(seconds / 60) + ":" + (seconds % 60).toFixed().pad(2, "0") );```
4. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
Mar 2006
Posts
69
Rep Power
29
Originally Posted by fatnic388
. . . how do you convert seconds (eg. 70) to minutes:seconds (1:10)?
I think you're going to need two variables: one to hold the minutes, the other to hold the seconds.

For example, something like the following (haven't tested):

Code:
```secVar0 = 70;                            // The initial data, in seconds
minVar = Math.floor(secVar0/60);  // The minutes
secVar = secVar0 % 60;              // The balance of seconds```
You should now have the minutes and seconds for further use or output however you like.

Regards,

David