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 : how to convert time to date (using moment)

I have moment(value).format("HH:mm") which is converting

2022-08-09T12:10:50.001Z

to

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

18:30

but I want to do it in opposite way.

Like I receive 18:30:00 from the database and I want this format 2022-08-09T12:10:50.001Z

Any solutions ?

>Solution :

What about this?

const time = moment('18:30:00', 'H:m:s');

console.log(time.toDate()); // Tue Aug 09 2022 18:30:00 GMT+0200
console.log(time.format("YYYY-MM-DDTHH:mm:ss.SSS[Z]")) // 2022-08-09T18:30:00.000Z
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