Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var Timer;
- var TotalSeconds;
- function CreateTimer(TimerID, Time) {
- Timer = document.getElementById(TimerID);
- TotalSeconds = Time;
- UpdateTimer();
- window.setTimeout("Tick()", 1000);
- }
- function Tick() {
- if (TotalSeconds <= 0)
- {
- CalculateResults();
- return;
- }
- TotalSeconds -= 1;
- UpdateTimer();
- window.setTimeout("Tick()", 1000);
- }
- function UpdateTimer() {
- var Seconds = TotalSeconds;
- var Days = Math.floor(Seconds / 86400);
- Seconds -= Days * 86400;
- var Hours = Math.floor(Seconds / 3600);
- Seconds -= Hours * (3600);
- var Minutes = Math.floor(Seconds / 60);
- Seconds -= Minutes * (60);
- var TimeStr = ((Days > 0) ? Days + " days " : "") + LeadingZero(Hours) + ":" + LeadingZero(Minutes) + ":" + LeadingZero(Seconds);
- Timer.innerHTML = TimeStr;
- }
- function LeadingZero(Time) {
- return (Time < 10) ? "0" + Time : + Time;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement