How to format a date in Moment.js

后端 未结 2 616
温柔的废话
温柔的废话 2021-01-16 21:18

I\'m having trouble formatting a date correctly in Moment.js. I\'m using the format function with format \"LLL D, YYYY\" so it should return something like \"Sep 15, 2016\".

相关标签:
2条回答
  • 2021-01-16 21:35

    From http://momentjs.com/docs/#/displaying/format/ we can see that "LLL" represents the format "Month name, day of month, year, time". It seems you want "Month day, year", which is "LL".

    Try:

    picker.format = 'LL';
    formatted = moment(picker.date).format(picker.format);
    console.log(formatted);
    

    Outputs (with today's date):

    September 15, 2016
    
    0 讨论(0)
  • 2021-01-16 21:37

    This should work...

    formatted = moment(picker.date).format('MMM D, YYYY')
    

    Ref: http://momentjs.com/docs/#/parsing/string-format/

    0 讨论(0)
提交回复
热议问题