You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
const target = new Date(location.hash.substr(1));
|
|
|
|
|
|
|
|
const second = 1000;
|
|
|
|
const minute = second*60;
|
|
|
|
const hour = minute*60;
|
|
|
|
const day = hour*24;
|
|
|
|
|
|
|
|
const update_countdown = () => {
|
|
|
|
const now = new Date();
|
|
|
|
const diff = target - now;
|
|
|
|
|
|
|
|
const timeleft = {};
|
|
|
|
timeleft.days = Math.floor(diff/day);
|
|
|
|
timeleft.hours = Math.floor(diff%day/hour);
|
|
|
|
timeleft.minutes = Math.floor(diff%day%hour/minute);
|
|
|
|
timeleft.seconds = Math.floor(diff%day%hour%minute/second);
|
|
|
|
|
|
|
|
Object.keys(timeleft).forEach((unit) => {
|
|
|
|
// retrieve value, cast it to string and optionally pad it with a leading 0
|
|
|
|
const value = timeleft[unit]
|
|
|
|
.toString()
|
|
|
|
.padStart(2, '0');
|
|
|
|
|
|
|
|
document.getElementById(unit).innerHTML = value;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
update_countdown();
|
|
|
|
setInterval(update_countdown, 500);
|