Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Two-digit year format for localized formats in Moment.js

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,

like image 471
Pierre Roudaut Avatar asked Jan 23 '17 11:01

Pierre Roudaut


1 Answers

var formatL = moment.localeData().longDateFormat('L');
var formatYearlessL = formatL.replace(/YYYY/g,'YY');
console.log(moment().format(formatYearlessL)); 
like image 85
Vladu Ionut Avatar answered Sep 29 '22 09:09

Vladu Ionut