The following code counts down to specific hour setHours
and then restarts the 24-hour countdown after that time. However, it takes the time off the user's computer so it'd be inaccurate in every country. How do I specify a timezone to the code so it's correct no matter where you are located?
<script>
(function () {
var start = new Date;
start.setHours(14, 0, 0); // 2pm
function pad(num) {
return ('0' + parseInt(num)).substr(-2);
}
function tick() {
var now = new Date;
if (now > start) { // too late, go to tomorrow
start.setDate(start.getDate() + 1);
}
var remain = ((start - now) / 1000);
var hh = pad((remain / 60 / 60) % 60);
var mm = pad((remain / 60) % 60);
var ss = pad(remain % 60);
document.getElementById('time').innerHTML =
hh + 'hrs ' + mm + 'mins ' + ss + 'secs';
setTimeout(tick, 1000);
}
document.addEventListener('DOMContentLoaded', tick);
})();
</script>`