How can I remove time from date with Moment.js?

后端 未结 11 2236
予麋鹿
予麋鹿 2020-11-28 03:04
formatCalendarDate = function (dateTime) {
    return moment.utc(dateTime).format(\'LLL\');
};

It displays: \"28 februari 2013 09:24\"

But

11条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-28 03:38

    For people like me want the long date format (LLLL) but without the time of day, there's a GitHub issue for that: https://github.com/moment/moment/issues/2505. For now, there's a workaround:

    var localeData = moment.localeData( moment.locale() ),
        llll = localeData.longDateFormat( 'llll' ),
        lll = localeData.longDateFormat( 'lll' ),
        ll = localeData.longDateFormat( 'll' ),
        longDateFormat = llll.replace( lll.replace( ll, '' ), '' );
    var formattedDate = myMoment.format(longDateFormat);
    

提交回复
热议问题