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

JS timestamp wrong – timezone setting

When setting a date from a timestamp using JS, I obtain the wrong hour.

var timestamp = 1548374400000 //In milliseconds.
var time_string =  new Date(timestamp).toLocaleString("en-GB",{timezone:"Europe/London"})
console.log(time_string)

Which outputs:

25/01/2019, 01:00:00

However when checking on the following website: https://www.epochconverter.com/timezones?q=1548374400000&tz=Europe%2FLondon

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

I obtain that this timestamp (1548374400000) corresponds to the date: Friday January 25, 2019 00:00:00 (am) in time zone Europe/London (GMT)

There is a one hour difference between these results that I cannot explain myself.

I have checked on this website to be sure this was an error on my side:
enter image description here

>Solution :

var timestamp = 1548374400000; // In milliseconds.
var time_string = new Date(timestamp).toLocaleString("en-GB", { timeZone: "Europe/London" });
console.log(time_string);

You just used the wrong keyword. Use code above should fix your problem.

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