我如何在流星中定义日期

how do i define a date in meteor

我正在尝试检索提交表单的日期。使用代码:

Template.SingleDailylog.helpers({
  date: function(){
    const id = FlowRouter.getParam('id');
    if (id) {
        profile = Dailylog.findOne({_id:id});
    }
    if (profile && profile.date) {
        logDate = profile.date;
    }
    if (logDate) {
      return moment(logDate).format('MM/DD/YYYY');
    }
    },

显示日期,但在控制台中显示:模板助手中的异常:ReferenceError:未定义 logDate 在 Object.date (http://localhost:3000/app/app.js?hash=b97240050e4c7c8657adb412270a5335856229b7:8546:5)

如果我用'name'替换'logDate':

Template.SingleDailylog.helpers({
  date: function(){
    const id = FlowRouter.getParam('id');
    if (id) {
        profile = Dailylog.findOne({_id:id});
    }
    if (profile && profile.date) {
        name = profile.date;
    }
    if (name) {
      return moment(name).format('MM/DD/YYYY');
    }
    },

我收到:弃用警告:提供的值不是可识别的 RFC2822 或 ISO 格式。 moment 构造回退到 js Date(),这在所有浏览器和版本中都不可靠。不鼓励使用非 RFC2822/ISO 日期格式,并将在即将发布的主要版本中将其删除。

像这样重写代码,以避免使用未声明的变量:

Template.SingleDailylog.helpers({
  date: function(){
    const id = FlowRouter.getParam('id');
    if (id) {
      const profile = Dailylog.findOne({_id:id});
      if (profile && profile.date) {
        return moment(profile.date).format('MM/DD/YYYY');
      }
    }
  }
})