I use moment.js to display the UTC date in the users local time zone:
var date = new Date(Date.UTC(2016,03,30,0,0,0)); var now = new Date(); var diff = (date.getTime()/1000) - (now.getTime()/1000); var textnode = document.createTextNode(moment(date).format('dddd, DD.MM.YYYY') + ' a las ' + moment(date).format('HH:mm A')); document.getElementsByClassName("date")[0].appendChild(textnode.cloneNode(true));
Then I use a variable diff
, to show a countdown timer.
I would like to show a different countdown timer for each in their local time zone. (Using the difference before midnight in your time zone, not in UTC)
But I try my best to make it work. Instead of using var date = new Date(Date.UTC(2016,03,30,0,0,0));
I probably need to use some moment.js function that gives me until midnight in users timezone.
The best example would be the new year. If I use UTC, everyone will have the same counter (9 hours left), but in different parts of the world this does not make sense. For someone in Australia, this should be 2 hours, and for someone in the US, 14 hours.
source share