Created
May 4, 2017 11:18
-
-
Save httpsterio/18da63c6a5c584b15bb191722d121cc8 to your computer and use it in GitHub Desktop.
template-literal-test.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let deadline = "05/05/2017 10:45"; | |
| function getTimeRemaining(endtime) { | |
| var t = Date.parse(endtime) - Date.parse(new Date()); | |
| var seconds = Math.floor(t / 1000 % 60); | |
| var minutes = Math.floor(t / 1000 / 60 % 60); | |
| var hours = Math.floor(t / (1000 * 60 * 60) % 24); | |
| var days = Math.floor(t / (1000 * 60 * 60 * 24)); | |
| return { | |
| total: t, | |
| days: days, | |
| hours: hours, | |
| minutes: minutes, | |
| seconds: seconds, | |
| }; | |
| } | |
| function initializeClock(id, endtime) { | |
| var clock = document.getElementById(id); | |
| var timeinterval = setInterval(function() { | |
| var t = getTimeRemaining(endtime); | |
| clock.innerHTML = | |
| `days: $t.days <br> | |
| hours: $t.hours <br> | |
| minutes: $t.minutes <br> | |
| seconds: $t.seconds`; | |
| if (t.total <= 0) { | |
| clearInterval(timeinterval); | |
| } | |
| }, 1000); | |
| } | |
| initializeClock("clock", deadline); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment