Hi i want this Javscript function to countdown how much time there is left untill the next day stars but i seem to get a problem when i want to automate it.
If i change this code
var eventDate = new Date();
eventDate.setDate(now.getDate() +1);
To this code it will work, but it is not automatic
var eventDate = new Date(2017, 03, 21);
So how can i make it automatic?
function countDown() {
var now = new Date();
var currentTime = now.getTime();
var eventDate = new Date();
eventDate.setDate(now.getDate() +1);
var eventTime = eventDate.getTime();
var remainingTime = eventTime - currentTime;
var sekunder = Math.floor(remainingTime / 1000);
var minutter = Math.floor(sekunder / 60);
var timer = Math.floor(minutter / 60);
sekunder %= 60;
minutter %= 60;
timer %= 24;
sekunder = (sekunder < 10) ? "0" + sekunder : sekunder;
minutter = (minutter < 10) ? "0" + minutter : minutter;
timer = (timer < 10) ? "0" + timer : timer;
var test = timer + ":" + minutter + ":" + sekunder;
document.getElementById("countdownTimer").textContent = test;
setTimeout(countDown, 1000);
}
countDown();
Also if anyone got the time, how do i make it countdown to my servers midnight time insted of the local computer time as Javascript will do?