1 Reply Latest reply on May 8, 2011 7:50 PM by Ned Murphy

    Countdown to a specific time (Not Midnight)

    WTDedula Level 1

      Hello All;

      I have to quickly make a countdown timer for a website that counts down to a specific date & time (Not midnight). I need like May 4th, 2011 at 9:10 AM.

       

      I used a tutorial to create a timer that counts down to midnight but need to modify it to countdown to a specific time other than midnight.

       

      Below is the code. Can anyone help me modify the code below. Thanks.

       

      Tim

       



      var today:Date = new Date();
      var currentYear = today.getFullYear();
      var currentTime = today.getTime();

      var targetDate:Date = new Date(currentYear,1,12);
      var targetTime = targetDate.getTime();
      if (targetTime <= 0) {
        gotoAndStop(3);
      }

      var timeLeft = targetTime - currentTime;
      var sec = Math.floor(timeLeft/1000);
      var min = Math.floor(sec/60);
      var hrs = Math.floor(min/60);
      var days = Math.floor(hrs/24);
      sec = String(sec % 60);
      if (sec.length < 2) {
        sec = "0" + sec;
      }
      min = String(min % 60);
      if (min.length < 2) {
        min = "0" + min;
      }
      hrs = String(hrs % 24);
      if (hrs.length < 2) {
        hrs = "0" + hrs;
      }
      days = String(days);
      var counter:String = days + ":" + hrs + ":" + min + ":" + sec;
      time_txt.text = counter;

        • 1. Re: Countdown to a specific time (Not Midnight)
          Ned Murphy Adobe Community Professional & MVP

          I haven't looked at the rest of the code, but if you say it works, then all you really need to do is adjust the targetDate arguments.

           

          The constructor for a Date object is...

           

          Date(year, month, date, hour, minute, second, millisecond)
           
          so just fill in the data you need instead of what you have....
           
          var targetDate:Date = new Date(year, month, date, hour, minute, second, millisecond);