【问题标题】:how can i take the value of the month of the variable CreatedAt如何获取变量 CreatedAt 月份的值
【发布时间】:2018-01-11 06:20:17
【问题描述】:

我有收款单,我想取变量“createdAt”的monthyear;我在应用程序中使用了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
    }
  }

}));

【问题讨论】:

标签: mongodb meteor momentjs meteor-blaze


【解决方案1】:

您可以尝试使用 moment 格式化日期,然后将“月”或“年”传递给 format()

例子:

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

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

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

【讨论】:

  • 非常感谢,这就是全部!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-01
  • 1970-01-01
  • 2021-12-16
  • 2013-06-23
相关资源
最近更新 更多