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

后端 未结 11 2178
予麋鹿
予麋鹿 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:50

    Use format('LL')

    Depending on what you're trying to do with it, format('LL') could do the trick. It produces something like this:

    Moment().format('LL'); // => April 29, 2016
    
    0 讨论(0)
  • 2020-11-28 03:52

    Sorry to jump in so late, but if you want to remove the time portion of a moment() rather than formatting it, then the code is:

    .startOf('day')
    

    Ref: http://momentjs.com/docs/#/manipulating/start-of/

    0 讨论(0)
  • 2020-11-28 03:55

    Okay, so I know I'm way late to the party. Like 6 years late but this was something I needed to figure out and have it formatted YYYY-MM-DD.

    moment().format(moment.HTML5_FMT.DATE); // 2019-11-08
    

    You can also pass in a parameter like, 2019-11-08T17:44:56.144.

    moment("2019-11-08T17:44:56.144").format(moment.HTML5_FMT.DATE); // 2019-11-08
    

    https://momentjs.com/docs/#/parsing/special-formats/

    0 讨论(0)
  • 2020-11-28 03:56

    You can use this constructor

    moment({h:0, m:0, s:0, ms:0})
    

    http://momentjs.com/docs/#/parsing/object/

    console.log( moment().format('YYYY-MM-DD HH:mm:ss') )
    
    console.log( moment({h:0, m:0, s:0, ms:0}).format('YYYY-MM-DD HH:mm:ss') )
    <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.min.js"></script>

    0 讨论(0)
  • 2020-11-28 03:57
    formatCalendarDate = function (dateTime) {
        return moment.utc(dateTime).format('LL')
    }
    
    0 讨论(0)
提交回复
热议问题