momentjs:moment.js中的弃用警告错误

时间:2018-07-16 13:36:38

标签: javascript momentjs

我需要帮助,我的代码警告我提供的值不是公认的ISO格式。

这是警告错误

  

弃用警告:提供的值不是公认的ISO格式。   的建设回落到js Date(),这是不可靠的   跨所有浏览器和版本。不建议使用非ISO日期格式   并将在即将发布的主要版本中删除。请参阅   http://momentjs.com/guides/#/warnings/js-date/了解更多信息。   参数:[0] _isAMomentObject:true,_isUTC:true,_useUTC:true,   _l:未定义,_i:2016-9-26 19:30,_f:未定义,_strict:未定义,_locale:[对象对象]

这是我的代码:

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: "")
};

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

1 个答案:

答案 0 :(得分:1)

这些值NioSocketConnector connector = new NioSocketConnector(); TextLineCodecFactory customTextLineCodecFactory = new TextLineCodecFactory(Charset.forName("UTF-8"), LineDelimiter.NUL, LineDelimiter.NUL); connector.getFilterChain().addLast("codec", new ProtocolCodecFilter(customTextLineCodecFactory)); connector.setHandler(this); IoSession session; for (;;) { try { ConnectFuture future = connector.connect(new InetSocketAddress("127.0.0.1", 8090)); future.awaitUninterruptibly(); session = future.getSession(); break; } catch (RuntimeIoException e) { System.err.println("Failed to connect"); e.printStackTrace(); Thread.sleep(5000); } } // wait until the summation is done session.write("sth"); session.getCloseFuture().awaitUninterruptibly(); connector.dispose(); comp.employmentdetails.fromdate的格式不是 ISO-8601 。以下是格式:

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

comp.employmentdetails.todate

有关更多信息,请检查here