2017-08-03 1 views
0

私は回収オーダーを持っています。の変数 "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 
    } 
    } 

})); 
+1

これまでに何を試みましたか? – VincenzoC

+0

ユーザーに表示するラベルや、プログラムできる値を探していますか? – zim

+0

こんにちは、私は必要があります:https://stackoverflow.com/questions/45464098/meteor-js-how-to-sum-records-per-month-of-the-same-collection/45464409#45464409 –

答えて

0

あなたは瞬間を使用して日付をフォーマットし、ちょうどformat()

例にに「月」または「年」を渡して試すことができます:

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

それとも、内蔵の機能を使用することができますこれらの値を取得するにはDOCS

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

ありがとう、これはすべてです! –

関連する問題