Home > Back-end >  js : how to convert time to date (using moment)
js : how to convert time to date (using moment)

Time:08-10

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

2022-08-09T12:10:50.001Z

to

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 ?

CodePudding user response:

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
  • Related