Home javascript Timer on JavaScript

Timer on JavaScript

Author

Date

Category

Help write a timer on JavaScript.
It is necessary that he counts the time to a specified date (time is read from the computer).
The timer should be displayed:

& lt; span class = "count-hour-1" & gt; 1 & lt; / span & gt;
& lt; span class = "Count-Hour-2" & gt; 0 & lt; / span & gt;
:
& lt; span class = "Count-min-1" & gt; 1 & lt; / span & gt;
& lt; span class = "Count-min-2" & gt; 7 & lt; / span & gt;
:
& lt; Span class = "Count-SEC-1" & gt; 5 & lt; / span & gt;
& lt; span class = "Count-SEC-2" & gt; 9 & lt; / span & gt;

No days, so if there are more days more than 1, you need to translate them into hours.
(For example, 2 days – 48 hours).

Throw references if such a timer is already implemented somewhere. I did not find unfortunately.


Answer 1, Authority 100%

there is an example

Here there is an example of a timer with a countdown, I hope with how to use these timers for your own purposes. You will figure it out.

& lt; script type = "text / javascript" & gt;
Function Timer () {
 var OBJ = Document.getelementByid ('Timer_Inp');
 obj.innerhtml--;
 if (obj.innerhtml == 0) {alert ('hello'); settimeout (function () {}, 1000);}
 ELSE {setTimeout (Timer, 1000);}
}
SetTimeout (Timer, 1000);
& lt; / script & gt;
& lt; div id = "Timer_Inp" & gt; 10 & lt; / div & gt;

Added

How to make from this what you need:

  1. Making a variable (hereinafter t), which is responsible for the remaining time (you can in seconds) (a little googled or ask the right questions, and you can find out how to do it).
  2. in the timer, reduce from this variable t subtract 1 second (here is not a particular mind, just small skills in programming. Again, you can google).
  3. Also in the timer we translate this variable t in 6 digits, and put them elements we need (similarly, you can find out).

Outcome: If you are not lazy, you can deal with it yourself 🙂


Answer 2, Authority 67%

It seems that you need.

UPD: Here you have a virtually ready solution. You can only write a conclusion in HTML.

& lt; script type = "text / javascript" & gt;
FUNCTION TIMER (DATE) {
  VAR S = (New Date). GetTime () - (new date ()). GetTime ();
  S = PARSEINT (S / 1000);
  VAR H = PARSEINT (S / 3600);
  S - = H * 3600;
  VAR M = PARSEINT (S / 60);
  S - = M * 60;
  Console.log (H + ':' + M + ':' + S);
  if ((New Date). GetTime () & GT; = (New Date ()). GetTime ()) SetTimeout ('Timer (\' '+ Date +' \ ');', 1000);
}
Timer ('September 1, 2013');
& lt; / script & gt;

Answer 3

This must approach: countdown timer on jQuery

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions