0 Replies - 331 Views - Last Post: 12 October 2011 - 11:23 AM

Topic Sponsor:

#1 STP_Captain_Slow  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 51
  • Joined: 08-October 10

Countdown Timer Accuracy

Posted 12 October 2011 - 11:23 AM

Hi

I have a countdown timer which i have found the code for, but at the momunt it only counts down to midnight of the date selected. How can i amend the code to countdown to a certain time of that day e.g. 10am 01/11/2011



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

var targetDate:Date = new Date(currentYear,11,19);
var targetTime = targetDate.getTime();

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;




Thanks in advance for any help!

Is This A Good Question/Topic? 0
  • +

Page 1 of 1