Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
62
rated 0 times [  63] [ 1]  / answers: 1 / hits: 18996  / 9 Years ago, thu, december 10, 2015, 12:00:00

My application sends an HTML file with javascript like this:



$(function () {
moment.locale('fr');
$('#datetimepicker9').datetimepicker({
viewMode: 'years',
locale: 'fr',
format: '' /* <========= problem! */
});
});


With moment, when I set to a locale, is there a way to get the short date format of the configuration like 'j F Y' for fr?



I found it but it's hack-ish:



moment()['_locale']['_longDateFormat']['L']


So my code now:



$(function () {
moment.locale('fr');
$('#datetimepicker9').datetimepicker({
viewMode: 'years',
locale: 'fr',
format: moment()['_locale']['_longDateFormat']['L']
});
});


I dont like that, is there a clean way to get the format?


More From » momentjs

 Answers
17

You can retrieve locale-specific format strings with the longDateFormat() of the current localeData():



moment.locale('fr');

var localeData = moment.localeData();
var dateFormat = localeData.longDateFormat('LL');

console.log(dateFormat); // D MMMM YYYY

[#64104] Tuesday, December 8, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
loganl

Total Points: 424
Total Questions: 86
Total Answers: 112

Location: Zimbabwe
Member since Thu, Jul 21, 2022
2 Years ago
;