Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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) 
like image 655
Patton Pierce Avatar asked Dec 30 '15 13:12

Patton Pierce


1 Answers

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.

like image 100
Xotic750 Avatar answered Sep 23 '22 14:09

Xotic750