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.

26 lines
754 B
JavaScript

const target = new Date('2019-06-21T10:54:00+02:00');
const second = 1000;
const minute = second*60;
const hour = minute*60;
const day = hour*24;
setInterval(() => {
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;
});
}, 500);