我有收集订单,我想取变量"createdAt“的月份和年份;我在应用程序中使用momentsjs。
Orders = new Mongo.Collection('orders');
Orders.attachSchema(new SimpleSchema({
'taxtotal':{type:Number},
'subtotal':{type:Number},
createdAt:{
type: Date,
autoValue: function() {
return new Date()
}
},
createdBy: {
type: String,
autoValue: function() {
return this.userId
}
}
}));发布于 2017-08-03 16:42:48
您可以尝试使用矩格式化日期,并将“月”或“年”传递给format()。
示例:
var month = moment(createdAt).format('M');
var year = moment(createdAt).format('YYYY');也可以使用内置函数检索这些值文档。
var month = moment(createdAt).month();
var year = moment(createdAt).year();https://stackoverflow.com/questions/45487688
复制相似问题