Skip to main content
Known Participant
December 16, 2012
Answered

Smart display of remaining time

  • December 16, 2012
  • 1 reply
  • 789 views

Hi there!

To acknowledge the users of my site about the remaining time of their sessions, I display a countdown in seconds.

But this is not very smart...

How can I display the remaining time in minutes and seconds?

(sessions are limited to 30mn)

Kind of display I wish to use: 16:39

This is the code I use:

count = 1800;

myCountDown = function () {

    count--;

};

countInterval = setInterval(myCountDown, 1000);

onEnterFrame = function () {

    countDownFld.text = count;

    if (count == 0) {

        clearInterval(countInterval);

        <some action>;

        <some another action>;

    }

};

Many thanks in advance for your help!

This topic has been closed for replies.
Correct answer Ned Murphy

If you have seconds and want to show minutes and seconds then you need to do a little math.  If you divide the number of seconds by 60 you get the number of minutes.  If you take the modulus of the seconds versus 60, you get the number of seconds.  So just use those two calculations to ge6t the minutes and seconds and display them in a textfield.

var minutes = Math.floor(count/60);

var seconds = count%60;

countDownFld.text = String(minutes)+":"+String(seconds);

and if you want to display leading zeroes you can do a conditional check to see if the numbers are < 10 and append them to a "0" if so.

if(seconds < 10) seconds = "0"+ seconds;

1 reply

Ned Murphy
Ned MurphyCorrect answer
Legend
December 16, 2012

If you have seconds and want to show minutes and seconds then you need to do a little math.  If you divide the number of seconds by 60 you get the number of minutes.  If you take the modulus of the seconds versus 60, you get the number of seconds.  So just use those two calculations to ge6t the minutes and seconds and display them in a textfield.

var minutes = Math.floor(count/60);

var seconds = count%60;

countDownFld.text = String(minutes)+":"+String(seconds);

and if you want to display leading zeroes you can do a conditional check to see if the numbers are < 10 and append them to a "0" if so.

if(seconds < 10) seconds = "0"+ seconds;

Germaris1Author
Known Participant
December 16, 2012

Crystal clear!

Thank you very much, Ned the Geek!

You made my day...

Best regards,

Gerard

PS: I want to congratulate here all of the "super members" like you, kglad, and so many others who helped us to solve our problems. So much time dedicated to the community. Thank you, thank you, thank you!!!

Ned Murphy
Legend
December 16, 2012

You're welcome.  Though it's not my place to say the same for others, I'll chance it... you're welcome.