自动过期XML元素

时间:2018-12-05 10:42:45

标签: javascript xml

我尝试使用JavaScript自动使XML元素过期。但是我的代码无法正确捕获到期日期。我该如何实现代码。

XML

 <offer>
    <cd expires="30/11/2018">
      <head>Lorem ipsum dolor sit amet, consectetur adipiscing elit.1</head>
      <image>https://upload.wikimedia.org/wikipedia/commons/thumb/5/52/Liliumbulbiferumflowertop.jpg/220px-Liliumbulbiferumflowertop.jpg</image>
    </cd>
</offer>

JavaScript

.filter(function(offer) {
  var today = new Date().setHours(0, 0, 0, 0);
  var dateToBeMatchedString = offer["@_expires"];
  if (!dateToBeMatchedString) return true;
  var dateToBeMatched = new Date(
    parseInt(dateToBeMatchedString.substring(6, 10)),
    parseInt(dateToBeMatchedString.substring(3, 5)),
    parseInt(dateToBeMatchedString.substring(0, 2))
  );
  return today <= dateToBeMatched;
});

0 个答案:

没有答案