REJAB Mehdi
REJAB Mehdi

Reputation: 3

Formatting a Date String into a Date

I want to format a string Date "14/06/2019 12:52" using moment library in order to manipulate a Date object and not a string.

I tried using moment library but didn't succeed to have a Date object

const myDate = moment('14-06-2019 12:52')

the const myDate is not of type Date.

Upvotes: 0

Views: 69

Answers (2)

arizafar
arizafar

Reputation: 3122

You need to provide the format also

const myDate = moment('14-06-2019 12:52', 'DD-MM-YYYY hh:mm');

Upvotes: 1

Alex
Alex

Reputation: 878

You could use moment().toDate();

Refer here for more info http://momentjs.com/docs/#/displaying/as-javascript-date/

Upvotes: 0

Related Questions