My countdown shows the wrong hours with my current location. It shows 6 hours difference from my time zone. My time zone is Asia/Dhaka.
How do I get the correct hours? days, Minutes, and Seconds are correct. Only problem with hours.
// Got this function from thisinterestsme
function calculateChristmasCountdown() {
//Get today's date.
var now = new Date();
//Get the current month. Add a +1 because
//getMonth starts at 0 for January.
var currentMonth = (now.getMonth() + 1);
//Get the current day of the month.
var currentDay = now.getDate();
//Work out the year that the next Christmas
//day will occur on.
var nextChristmasYear = now.getFullYear();
if (currentMonth == 12 && currentDay > 25) {
//This year's Christmas Day has already passed.
nextChristmasYear = nextChristmasYear + 1;
}
var nextChristmasDate = nextChristmasYear + '-12-25T00:00:00.000Z';
var christmasDay = new Date(nextChristmasDate);
//Get the difference in seconds between the two days.
var diffSeconds = Math.floor((christmasDay.getTime() - now.getTime()) / 1000);
var days = 0;
var hours = 0;
var minutes = 0;
var seconds = 0;
//Don't calculate the time left if it is Christmas day.
if (currentMonth != 12 || (currentMonth == 12 && currentDay != 25)) {
//Convert these seconds into days, hours, minutes, seconds.
days = Math.floor(diffSeconds / (3600 * 24));
diffSeconds -= days * 3600 * 24;
hours = Math.floor(diffSeconds / 3600);
diffSeconds -= hours * 3600;
minutes = Math.floor(diffSeconds / 60);
diffSeconds -= minutes * 60;
seconds = diffSeconds;
}
//Add our counts to their corresponding HTML elements.
document.getElementById('cws_xmas_days').innerHTML = days;
document.getElementById('cws_xmas_hours').innerHTML = hours;
document.getElementById('cws_xmas_minutes').innerHTML = minutes;
document.getElementById('cws_xmas_seconds').innerHTML = seconds;
setTimeout(calculateChristmasCountdown, 1000);
}
calculateChristmasCountdown();
<span id="cws_xmas_days"></span> days
<span id="cws_xmas_hours"></span> hours
<span id="cws_xmas_minutes"></span> minutes
<span id="cws_xmas_seconds"></span> seconds