Maxi M. Maxi M. - 1 year ago 64
Javascript Question

Date format with Moment.js or classic JS, change places of day and month?

I get date value from my source in this format:
02.08.2016 / Day.Month.Year, it's correct.

but JavaScript understand this inverse, Month.Day.Year.

I tried some ways with Moment.js like:


My JsFiddle is:
There are some results visible, see please output, variable dateThree: Invalid date

My question is, how can I do it with Moment.js or classic JavaScript?

Answer Source

You can specify the format of the input date string like this.

moment('15.08.2016', 'DD.MM.YYYY').format('MM.DD.YYYY');