Moment.js - change the format of a formatted past date

I need to get the past date using the moment. js ( http://momentjs.com/ ), which I get in a specific format:

moment('31.10.2013', 'dd.mm.yy');

This returns me a strange answer when I see the current date in the option _d:

// returns
_a: Array[7]
_d: Wed Nov 06 2013 00:10:00 GMT+0200 (EET)
_f: "dd.mm.yy"
_i: "26.10.2013"
_isUTC: false
_l: undefined
_pf: Object
_strict: undefined

I assume this is a formatting issue:

moment('31.10.2013', 'dd.mm.yy').format('YYYY/MM/DD');
// returns current date (why??!)
// "2013/11/06"

So what is wrong here, can I format the past date?

+4
source share
1 answer

At first I thought it was a format, but in fact it is a format, lowercase means something different from uppercase letters both inside and outside.

moment('31.10.2013', 'DD.MM.YYYY').format('YYYY/MM/DD')
>> "2013/10/31"

moment('31.10.2013', 'dd.mm.yyyy').format('YYYY/MM/DD')
>> "2013/11/06"

So fix your input mask, not the format.

+10

All Articles