Skip to content Skip to sidebar Skip to footer

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 wa

Solution 1:

You are essentially building your target time as:

newDate("Dec 16, 2020 03:10:25")

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:

newDate("2020-12-16T02:10:25Z")

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:

newDate("2020-12-16T03:10:25+01:00")

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

Solution 2:

You may use getTimezoneOffset to further adjust the time so that everyone can use the say UTC time. (The time-zone offset is the difference, in minutes, between UTC and local time. )

var offset=newDate().getTimezoneOffset();
console.log(offset);

Post a Comment for "Javascript Countdown Timer Timezone Problem"