AngularJS将祖鲁日期转换为格式化日期

时间:2018-02-23 07:57:37

标签: html angularjs

我在AngularJS中有一个从HTML获取日期的函数。 当我将日期打印到控制台时,日期格式为:

Tue Apr 06 2021 00:00:00 GMT + 0300(耶路撒冷夏令时)

我需要将日期转换为" yyyy-MM-dd"或" dd-MM-yyyy"。 当我将日期转换为String时,日期变为昨天的一天。

c.couponByDate = [];

  c.getCouponByDateForm = function() {
    console.log("Zulu Date: " + c.couponFields.endDate);
    //This line of code makes the date one day off: yesterday.
    c.couponFields.endDate = c.couponFields.endDate.toISOString().replace(/T.*$/g,'');
    console.log("Date to String: " + c.couponFields.endDate);
    c.couponByDate = c.getCouponByDateResource.query(c.couponFields, function() {
      if (c.couponByDate.length > 0) {
        c.couponByDate.forEach(function(coupon){
          c.couponFields = coupon;
          c.couponByDateTableDiv = true;
          c.couponByDateExceptionDiv = false;
        })
      } else {
        c.error("No coupons by date: " + c.couponFields.endDate + " were found");
        c.couponByDateExceptionDiv = true;
        c.couponByDateTableDiv = false;
      }
    }, function() {
      c.error("Request could not be completed");
      c.couponByDateExceptionDiv = true;
      c.couponByDateTableDiv = false;
    });
  }

<td>End Date: {{coupon.endDate | date: 'dd/MM/yyyy'}}</td>

0 个答案:

没有答案