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

How to turn an array of miliseconds into date format mm-dd-yyyy

i have the next array of dates in miliseconds

const dates = date?.rangeOfDates
console.log(dates)
(4) [1661281243730, 1661454043730, 1661886043730, 1661713243730]

Im trying to turn it into Date format the next way:

const listOfDates = new Date(dates).toLocaleDateString()

It gives me an Invalid Date error in the console but when I try to change it manually in the next way it works good:

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

console.log(new Date(1661281243730).toLocaleDateString())
--> 8/23/2022

>Solution :

Just use an array map to convert it.

const array = [1661281243730, 1661454043730, 1661886043730, 1661713243730];
array.map(x => new Date(x).toLocaleDateString());
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