Inserting a momentjs object in Meteor Collection

前端 未结 3 1313
被撕碎了的回忆
被撕碎了的回忆 2021-01-11 18:16

I have a simple Meteor collection and I am trying to insert a document that has a momentjs property into it. So I do:

docId = Col.insert({m: moment()});
         


        
3条回答
  •  甜味超标
    2021-01-11 19:17

    I strongly recommend storing dates as Date objects and using moment to format them after they are fetched. For example:

    Posts.insert({message: 'hello', createdAt: new Date});
    

    Then later when you want to display the date:

    var date = Posts.findOne().createdAt;
    moment(date).format('MMMM DD, YYYY');
    

提交回复
热议问题