【问题标题】:momentjs : Deprecation warning error in moment.jsmomentjs:moment.js 中的弃用警告错误
【发布时间】:2018-12-24 01:57:01
【问题描述】:

我需要帮助 我收到关于我的代码的警告,其中提供的值不是可识别的 ISO 格式。

这是警告错误

弃用警告:提供的值不是可识别的 ISO 格式。 moment 构建回退到 js Date(),不可靠 跨所有浏览器和版本。不鼓励使用非 ISO 日期格式 并将在即将发布的主要版本中删除。请参阅 http://momentjs.com/guides/#/warnings/js-date/ 了解更多信息。 参数:[0] _isAMomentObject:真,_isUTC:真,_useUTC:真, _l: undefined, _i: 2016-9-26 19:30, _f: undefined, _strict: undefined, _locale: [object Object]

这是我的代码:

var componentDetails = {
  componentName: comp.componentName,
  companyName: comp.employerdetails.companyname,
  fromDate: (comp.employmentdetails.fromdate)?moment(comp.employmentdetails.fromdate).format("DD-MM-YYYY"): comp.employmentdetails.fromdate,
  toDate: (comp.employmentdetails.todate&&comp.employmentdetails.todate!='Present')?moment(comp.employmentdetails.todate).format("DD-MM-YYYY"): comp.employmentdetails.todate,
  designation: comp.employmentdetails.designation,
  currency: comp.employmentdetails.currency,
  ctc: comp.employmentdetails.lastctc,
  period: comp.employmentdetails.period,
  senderName: req.session.loggedInUser.firstName+" "+req.session.loggedInUser.lastName,
  empCode: comp.employmentdetails.empid,
  reason: (comp.others?comp.others.reasonforleaving: "")
};

所以上面的部分只是我得到错误我该怎么办?

【问题讨论】:

标签: javascript momentjs


【解决方案1】:

这些值 comp.employmentdetails.fromdatecomp.employmentdetails.todate 不是 ISO-8601 格式。以下是格式:

ISO 8601 字符串需要日期部分。

2013-02-08  # A calendar date part
2013-W06-5  # A week date part
2013-039    # An ordinal date part

20130208    # Basic (short) full date
2013W065    # Basic (short) week, weekday
2013W06     # Basic (short) week only
2013050     # Basic (short) ordinal date

更多信息请查看here

【讨论】:

  • k 但是在我的代码中我需要把格式放在哪里?请告诉我,因为我已经改变了这种格式,但不起作用
  • @Prakash 您从哪里获得 comp.employmentdetails.fromdatecomp.employmentdetails.todate 以及您以什么格式获得这些值?
  • @Prakash 该格式需要作为矩构造的第二个参数传递。 See here
猜你喜欢
  • 1970-01-01
  • 2012-08-02
  • 2020-09-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-22
  • 1970-01-01
相关资源
最近更新 更多