Skip to main content
Participant
February 17, 2012
Answered

Can't get countdown clock to show the correct time

  • February 17, 2012
  • 1 reply
  • 1052 views

I have changed my newDate to see where the problem lies but cannot get it to match my target time to 2/22/2012 7pm

this.onEnterFrame = function() {

    var today = new Date();

   

    var currentYear = today.getFullYear();

    var currentTime = today.getTime();

   

    var targetDate = new Date(2012, 2, 31, 7);

    var targetTime = targetDate.getTime();

    var timeLeft = targetTime-currentTime;

    //var timeLeft = 900000000000;

   

    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_days.text = days-31

    time_hrs.text = hrs

    time_mins.text = min

    time_secs.text = sec

};

This topic has been closed for replies.
Correct answer kglad

i'm pointing out that targetDate is not 2/22/12 at 7pm.  if it were it would look like:

var targetDate = new Date(2012, 1, 22, 19);

1 reply

kglad
Community Expert
Community Expert
February 17, 2012

  var targetDate = new Date(2012, 2, 31, 7);

is march 31, 2012, 8am

BigChumpAuthor
Participant
February 17, 2012

are yu saying just shift the date to compensate?

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
February 17, 2012

i'm pointing out that targetDate is not 2/22/12 at 7pm.  if it were it would look like:

var targetDate = new Date(2012, 1, 22, 19);