Skip to content
Advertisement

Javascript countdown timer timezone problem

is it possible to have the countdown timer same for all people regardless of their timezone, when i put a date now the timer will show different depending on the timezone, and i want them to sync up so everyone get the same time, because now the “DONE” will display at different times depending on the country.

heres the code Thanks for any help! 🙂

JavaScript

Advertisement

Answer

You are essentially building your target time as:

JavaScript

That’s a non-standard format, and is going to be interpreted in terms of local time by most browsers.

Instead, pick a UTC-based point in time, and pass it in ISO 8601 / RFC 3339 format.

For example, if you meant 3:10:25 in a time zone with a UTC+1 offset, subtract 1 hour to get 2:10:25 UTC, represented like this:

JavaScript

Use values in that format in your source array and everyone will have the same target for the countdown. Keep in mind that the Z at the end means UTC, so don’t forget to include that. 🙂

Alternatively, you could use local time and the local offset that’s in effect for that time, rather than subtracting. That looks like this:

JavaScript

You can use either form, depending on which is easier for you.

Advertisement