最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Moment.js(moment()。format())不能代替Date.now

运维笔记admin22浏览0评论

Moment.js(moment()。format())不能代替Date.now

Moment.js(moment()。format())不能代替Date.now

我在使用js时刻转换日期时间时收到此错误:

CastError:值“ Oct 11th 19,23:57”的日期转换失败]

在路径“日期”。 Date.now可以工作,但是我想对其进行格式化,如下所示。有解决方案吗?

let User = new Schema({
    user: {
        type: String,
        required: true
    },
    date: {
        type: Date,
        default: moment().format("MMM Do YY, HH:mm")
    }
});
回答如下:

函数moment().format("MMM Do YY, HH:mm")返回一个字符串,那么您应该将type参数传递给String字段>

发布评论

评论列表(0)

  1. 暂无评论