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

Converting epoch timestamp into a readable date

I’m retrieving a value which is supposed to be a epoch timestamp from a database and trying to convert it back to a date format to display it into a screen.

I can see that I’m retrieving the correct value i.e. 1644537600 which should represent Friday, 11 February 2022 00:00:00.

When I do the following var date = new Date(parseInt(timestamp)); I get Tue Jan 20 1970 01:48:57

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 tried to divide timestamp / 1000 or 1000000 but I get the same result.

It could be with date formatting but struggling to make it work.

>Solution :

That epoch is in seconds, you need to multiply it by 1000.

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