我如何获取变量 CreatedAt 的月份值

how can i take the value of the month of the variable CreatedAt

我有收单,我想取变量"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
    }
  }

}));

您可以尝试使用 moment 格式化日期,然后将 'month' 或 'year' 传递给 format()

示例:

var month = moment(createdAt).format('M');
var year  = moment(createdAt).format('YYYY');

或者您可以使用内置函数检索这些值DOCS

var month = moment(createdAt).month();
var year  = moment(createdAt).year();