Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

UTC date time why does time zone not work?

Why can’t I take a time and set it to another zone? I want to take a string of a date and time that is static and change it to a different time zone and get result.

var d = new Date("2022-05-18T19:48:32.000+00:00");
d.toLocaleString('en-US', { timeZone: 'America/New_York' });

alert(d);

No matter what I do, it says my local computer time on my computer in Denver.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

d.toLocaleString('en-US', { timeZone: 'America/New_York' }); returns a string, but you’re not setting it to a variable. Try d = d.toLocaleString('en-US', { timeZone: 'America/New_York' });

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading