Moment.js: how to get a short date format?

My application sends the HTML file with javascript as follows:

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

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

I found it, but it hacked:

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

So now my code is:

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

I don't like it, is there a clean way to get the format?

+4
source share
2 answers

You can get format strings attached to the language using the longDateFormat() current onelocaleData() :

moment.locale('fr');

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

console.log(dateFormat); // D MMMM YYYY
+3
source

Later versions of the .js moment have localized formatting - http://momentjs.com/docs/#/displaying/format/

, , .

. .

LT 8:30 PM

LTS 8:30:25 PM

, , L 09/04/1986

l 9/4/1986

, , LL 4 1986 . ll 4 1986 .

, , , LLL 4 1986 8:30

lll 4 1986 8:30

, , , , LLLL , 4 1986 8:30

llll Thu, Sep 4 1986 8:30 PM

L LL LLL LLLL LT 1.3.0. l ll lll llll 2.0.0. LTS 2.8.4.

, :

var formattedDate = moment(d).format("l");
+2

Source: https://habr.com/ru/post/1619419/


All Articles