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