3 Replies Latest reply on Dec 16, 2012 11:57 AM by Ned Murphy

    Smart display of remaining time

    Germaris Level 1

      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!

        • 1. Re: Smart display of remaining time
          Ned Murphy Adobe Community Professional & MVP

          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;

          • 2. Re: Smart display of remaining time
            Germaris Level 1

            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!!!

            • 3. Re: Smart display of remaining time
              Ned Murphy Adobe Community Professional & MVP

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