How can I convert a date into another format with moment.js?

Viewed 32

I try to convert my date into another date with moment.js (https://momentjs.com/)

var date = "05.06.2020 10:46";
var DateCreated = moment(date, 'DD.MM.YYYY HH:MM').format('Y-m-d');

But the output is "invalid Date".

1 Answers

var DateCreated = moment(date, 'DD.MM.YYYY HH:MM').format('Y-m-d');

Don't you need HH:mm small m for minutes? 46 won't match any month, and that is your problem :)

Related