Is there a way in Moment.js to obtain a short year format (two digits only) for a localized date ?
moment().format('l'); // 1/23/2017
moment().format('<someSpecialFormat>'); // expected: 1/23/17
Any help or link to a related topic would be much appreciated.
Thanks,
Is there a way in Moment.js to obtain a short year format (two digits only) for a localized date ?
moment().format('l'); // 1/23/2017
moment().format('<someSpecialFormat>'); // expected: 1/23/17
Any help or link to a related topic would be much appreciated.
Thanks,
Share Improve this question asked Jan 23, 2017 at 11:03 Pierre RoudautPierre Roudaut 1,0731 gold badge19 silver badges33 bronze badges 1- You can't expect to know what a user expects to see for date formats. Far better to use an unambiguous format that uses the month name, perhaps allowing the user to select the language so for French, you might use 1-jan-2017 or 1 janvier, 2017. – RobG Commented Jan 23, 2017 at 13:07
2 Answers
Reset to default 13var formatL = moment.localeData().longDateFormat('L');
var formatYearlessL = formatL.replace(/YYYY/g,'YY');
console.log(moment().format(formatYearlessL));
moment(/Date Object/).format('MM/DD/YY');