【问题标题】:Date generated by moment.js having invalid propertymoment.js 生成的日期具有无效属性
【发布时间】:2015-09-04 00:34:08
【问题描述】:

下面的函数给了我下一个营业日期:

function nextBusinessDate() {

      var today = moment();
      var tomorrow = today.add(1, 'days');

      // if saturday
      if (tomorrow.day() === 6) {
        tomorrow = tomorrow.add(2, 'days');
      } else if (tomorrow.day() === 0) {
        tomorrow = tomorrow.add(1, 'days');
      }

      return new Date(tomorrow._d);
    }

它返回的日期如下所示:

myDate = nextBusinessDate();

// This is what myDate looks like in developer console
myDate: Fri Jun 19 2015 07:24:40 GMT-0400 (EDT)
__proto__: Invalid Date

我面临的问题是这不会存储在 firebase 中(我相信它使用 mongo)

我在这里错过了什么?

【问题讨论】:

标签: javascript momentjs


【解决方案1】:

在这个答案https://stackoverflow.com/a/26744045/1167456 中,您不应该使用 _d 方法,因为它是 API 中的私有方法。已经有一个内置转换器到 javascript 日期的时刻对象:.toDate()

您的退货线路应如下所示:

return tomorrow.toDate();

【讨论】:

    【解决方案2】:

    您不应该使用私人d。尝试使用.toDate()

    【讨论】:

      猜你喜欢
      • 2014-02-27
      • 1970-01-01
      • 1970-01-01
      • 2017-04-04
      • 1970-01-01
      • 2013-09-29
      • 2017-01-22
      • 1970-01-01
      • 2016-04-05
      相关资源
      最近更新 更多