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

    Join Date
    Aug 2006
    Posts
    13
    Rep Power
    0

    Unhappy 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??

    Can someone with a higher IQ than me please help?
  2. #2
  3. i don't do negative rep
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2006
    Posts
    760
    Rep Power
    705
    70 modulo 60, which in javascript is written as
    Code:
    70 % 60
    some character references
    universally acclaimed as "fundie of the worst kind"
    "the stubborn old loser whose high point of the day is making immature remarks and counting his rep points on an internet message board"
    stop bitching about lower case - it's my trademarkô
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Sep 2003
    Posts
    508
    Rep Power
    17
    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") );
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2006
    Posts
    68
    Rep Power
    24
    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

IMN logo majestic logo threadwatch logo seochat tools logo