ChristmasRocks
New Coder
I have a Christmas countdown and would like to change the timer to a July 4th timer. I've tried to change the dates in the script but haven't had any luck. Was wondering if someone could give me a hand. Thanks!
Code:
const days = document.getElementById('days'),
hours = document.getElementById('hours'),
minutes = document.getElementById('minutes'),
seconds = document.getElementById('seconds');
setInterval(() => {
findDate();
});
function findDate () {
let currentTime = new Date(),
christmasYear = currentTime.getFullYear();
//getMonth() method returns the month from 0 to 11
if(currentTime.getMonth() == 11 && currentTime.getDate() > 25){
christmasYear += 1;
}
let christmasTime = new Date(christmasYear, 11, 25);
let dateDiff = Math.floor(christmasTime - currentTime);
let DAYS = 0 , HOURS = 0, MINUTES = 0, SECONDS = 0;
if(currentTime.getMonth( ) !== 11 || (currentTime.getMonth() == 11 && currentTime.getDate() !== 25)) {
DAYS = Math.floor(dateDiff / (1000 * 60 *60 *24));
HOURS = Math.floor((dateDiff) % (1000 * 60 * 60 * 24) / (1000 * 60 * 60));
MINUTES = Math.floor((dateDiff % (1000 * 60 * 60)) / (1000 * 60));
SECONDS = Math.floor((dateDiff) % (1000 * 60) / 1000);
}
displayDate(setZero(DAYS), setZero(HOURS),setZero(MINUTES),setZero(SECONDS))
}
function displayDate(d,h,m,s) {
days.innerHTML = d;
hours.innerHTML = h;
minutes.innerHTML = m;
seconds.innerHTML = s;
}
function setZero(timeValue) {
if(timeValue < 10){
timeValue = "0" + timeValue;
}
return timeValue;
}