Is it possible to create a timer in jscript that you can manually change without it being affected by timezones?
Posted
by
Lixorp
on Stack Overflow
See other posts from Stack Overflow
or by Lixorp
Published on 2014-08-25T04:04:53Z
Indexed on
2014/08/25
4:20 UTC
Read the original article
Hit count: 136
is it possible to create a timer where I can manually set the hours each day to a set number of hours but still remains accurate? For example; if I set the countdown for 5 hours at 2pm I want the timer to stop as soon as it hits 7pm. Also, when I set the timer for 5 hours I would like everyone in the world to see it countdown from 5 hours, no matter what the time is in their country. In the format: days hours minutes seconds.
The reason I want to do this is for a streamer's website. He needs a flexible timer which can be manually changed and is the same worldwide for his viewers to know when he starts streaming.
The current timer we're using at the moment;
setInterval(function(){
var currentTime = new Date();
if(currentTime.getHours() > 19){
var countdownHours = (24 - currentTime.getHours()) + 19;
}else if(currentTime.getHours() < 19){
var countdownHours = 19 - currentTime.getHours();
}else{
var countdownHours = 0;
}
var countdownMins = 59 - currentTime.getMinutes();
var countdownSecs = 60 - currentTime.getSeconds();
$('#countdown-days h1').text('0');
$('#countdown-hours h1').text(countdownHours);
$('#countdown-minutes h1').text(countdownMins);
$('#countdown-seconds h1').text(countdownSecs);
}, 1000);
As you can tell it isn't ideal for what we need it for since it counts down to 7pm in the timezone you're in.
Any help/examples would be greatly appreciated,
Thank you in advance, Lixorp.
© Stack Overflow or respective owner