Patton Pierce Patton Pierce - 4 years ago 121
HTML Question

How do I change the time zone in JavaScript?

I've been working on a time app for JS and I was wondering, how could I change the time zone. See, I live in the eastern time zone of North America, and i don't like converting it to the International Timezone. So here is my Code.

<button type="button"
onclick="document.getElementById('time').innerHTML = Date()">
Click me to display Date and Time.</button>

<p id="time"></p>

When I click the button, I get,

Wed Dec 30 2015 13:40:25 GMT+0000 (UTC)

But I want it to be,
Wed Dec 30 2015 8:40:25 (EST)
Can anybody help me?

Answer Source

Date.prototype.toString is supposed to give you a string in your local time (as configured on your client).

When you click Run code snippet this should show an alert dialog with your local time string (toString is implicitly called, like in your example);

alert(new Date());

If it does give you the expected result then either you client timezone is not configured correctly or the browser you are using is bugged.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download