Can I set the local time zone in my browser through Javascript?

I know that I can get the local timezone offset through the new Date (). getTimeZoneOffset (). But where did Javascript get this information? Is there a way I can set it so that all future Date objects have the offset that I want? I tried to find the DOM in Firebug but couldn't find anything.

What I'm trying to accomplish is to convert an era into a readable format, but it should be in US / Central, regardless of browser settings. Because I use US / Central, this is not a fixed difference from GMT. So instead of a bunch of super nasty conversion steps, why can't I just tell Javascript that I am in the US / Central?

+8
javascript timezone
source share
3 answers

I know that I can get the local timezone offset through the new Date (). getTimeZoneOffset (). But where did Javascript get this information?

The implementation of ECMAScript is expected to determine the local time zone setting.

Is there a way to set it so that all future Date objects have the offset I want?

Not.

So, instead of a bunch of super nasty conversion steps, why can't I just tell Javascript that I'm in US / Central?

Have you considered using the library ?

+4
source share

Moment-Timezone currently allows you to set the default time zone of the browser using moment.tz.setDefault() .

You will need to use moment() instead of Date() , but this is still a good update on top of the weird JS date object.

+4
source share

I understand this is an old post, but momentJS is a powerful javascript library for managing date and time objects

+1
source share

All Articles