formatCalendarDate = function (dateTime) {
    return moment.utc(dateTime).format('LLL');
};

它显示:“2013年2月28日09:24”

但是我想把最后的时间去掉。我该怎么做呢?

我用的是Moment.js。


当前回答

formatCalendarDate = function (dateTime) {
    return moment.utc(dateTime).format('LL')
}

其他回答

在更新版本的moment.js中,你也可以这样做:

var dateTime = moment();

var dateValue = moment({
    year: dateTime.year(),
    month: dateTime.month(),
    day: dateTime.date()
});

见:http://momentjs.com/docs/ /解析/对象/。

试试这个:

moment.format().split("T")[0]

好吧,我知道我来晚了。大概晚了6年,但这是我需要弄清楚的东西,并将其格式化为YYYY-MM-DD。

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

您也可以传入一个参数,如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/

尝试new Date().toDateString()

推荐-“2022年六月17日”

moment(date).format(DateFormat)

这里的DateFormat应该是DateFormat = 'YYYY-MM-DD'