4 Replies Latest reply on Oct 17, 2012 10:28 AM by joel_pau

    Digital Clock Displays But Doesnt Update Time

    tdemidio

      This is the code I have in Edge Animate under compostionReady:

       

      function updateClock ()

      {

        var currentTime = new Date ();

       

       

        var currentHours = currentTime.getHours ();

        var currentMinutes = currentTime.getMinutes ();

        var currentSeconds = currentTime.getSeconds ();

       

       

        // Pad the minutes and seconds with leading zeros, if required

        currentMinutes = ( currentMinutes < 10 ? "0" : "" ) + currentMinutes;

        currentSeconds = ( currentSeconds < 10 ? "0" : "" ) + currentSeconds;

       

       

        // Choose either "AM" or "PM" as appropriate

        var timeOfDay = ( currentHours < 12 ) ? "AM" : "PM";

       

       

        // Convert the hours component to 12-hour format if needed

        currentHours = ( currentHours > 12 ) ? currentHours - 12 : currentHours;

       

       

        // Convert an hours component of "0" to "12"

        currentHours = ( currentHours == 0 ) ? 12 : currentHours;

       

       

        // Compose the string for display

        var currentTimeString = currentHours + ":" + currentMinutes + ":" + currentSeconds + " " + timeOfDay;

       

       

        // Update the time display

        document.getElementById("Stage_clock").firstChild.nodeValue = currentTimeString;

       

      };

       

       

                             

                updateClock();

                setsetInterval('updateClock()', 1000 );

       

       

       

      I'm trying to have a digital clock display on the page and with the code above it does show up but doesnt update the time. You only see the numbers of that initial second the page loads. Any help is appreciated!

        • 1. Re: Digital Clock Displays But Doesnt Update Time
          elainecc Adobe Employee

          Hi, tdemidio-

           

          I see "setsetInterval" - could that be the reason your code doesn't work?

           

          -Elaine

          • 2. Re: Digital Clock Displays But Doesnt Update Time
            joel_pau Level 5

            Hi,

             

            Well, setInterval() must be within the function [updateClock()].

            I rewrite your code using Edge API: sym.$("clock") is a text box on Stage.

            I like setTimeout().

             

            compositionReady:

             

            //function updateClock(){

            var updateClock = function(){

             

                       var clock = sym.$("clock"); //

                       var currentTime = new Date ();

                       var currentHours = currentTime.getHours ();

                       var currentMinutes = currentTime.getMinutes ();

                       var currentSeconds = currentTime.getSeconds ();

             

                       currentMinutes = ( currentMinutes < 10 ? "0" : "" ) + currentMinutes;

                       currentSeconds = ( currentSeconds < 10 ? "0" : "" ) + currentSeconds;

             

                       var timeOfDay = ( currentHours < 12 ) ? "AM" : "PM";

             

                       currentHours = ( currentHours > 12 ) ? currentHours - 12 : currentHours;

                       currentHours = ( currentHours == 0 ) ? 12 : currentHours;

             

                       var currentTimeString = currentHours + ":" + currentMinutes + ":" + currentSeconds + " " + timeOfDay;

                       clock.html(currentTimeString); //

             

                       setTimeout(updateClock, 1000); //

             

                     //document.getElementById("Stage_clock").firstChild.nodeValue = currentTimeString;

                     //setInterval('updateClock()', 1000);

            };

             

            updateClock();

            • 3. Re: Digital Clock Displays But Doesnt Update Time
              tdemidio Level 1

              Joel,

               

              Thank You!! That did it. Greatly appreciated!

               

              Tiffany

              • 4. Re: Digital Clock Displays But Doesnt Update Time
                joel_pau Level 5

                Thanks.

                Please mark this as 'Answered' - it will help others on the forum -

                reponse.jpg