最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

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

IT培训 admin 4浏览 0评论

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字段>

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. 暂无评论