检索剩余API中的日期时的无效日期

时间:2019-04-03 08:55:24

标签: ionic-framework

我已经从Rest API检索了日期。结果变为无效日期。下面是我的代码。如果格式错误,请您帮我吗?

ngOnInit() {
    this.reportList$ = [];
    from(this.mcsService.getReportList().then(res => {
      for (let item of res.data.items as ReportSummaryItem[]) {
        let itemDate = new Date(item.createdOn);
        item.createdOn = itemDate.toLocaleDateString('en-GB') + ' ' + itemDate.toLocaleTimeString();
        console.log("Report Created Date"+item.createdOn);
        this.reportList$.push(item);
      }
      this.ref.detectChanges();
      return res.data.items;
    }));
  }

这是Rest API中检索日期的函数。

function getRows(req, res) {
    var parameter = { 'createdBy': req.user.username };
    var limitParam = '';
    var offsetParam = '';

    if (typeof req.query.offset === 'undefined') {
        offsetParam = ' OFFSET 0 ';
    } else {
        offsetParam = ' OFFSET ' + req.query.offset;
    }

    if (typeof req.query.limit === 'undefined') {
        limitParam = ' ROWS FETCH NEXT 100 ROWS ONLY ';
    } else {
        limitParam = ' ROWS FETCH NEXT ' + req.query.limit + ' ROWS ONLY ';
    }


    req.oracleMobile.database.sql(
        'SELECT tr."id", tr."observation", '
        + 'TO_CHAR(tr."createdOn" AT TIME ZONE \'+00:00\', \'dd-MON-yy\') as "createdOn" '
        + 'FROM "' + req.tarTable + '" tr ' +
        ' WHERE tr."createdBy" = :createdBy ' +
        ' ORDER BY tr."createdOn" desc ' + offsetParam + limitParam, parameter
    ).then(
        function (result) {
            res.status(result.statusCode).send(result.result);
        }, function (err) {
            res.status(err.statusCode).send(errorHandler.restErrorHandler(err));
        }
    );
}

1 个答案:

答案 0 :(得分:0)

我认为返回日期的格式不兼容。最好按照ISO 8601(yyyy-mm-ddThh:mm:ss.ffffff)对其进行格式化。

将您的SQL更改为:

+ 'TO_CHAR(tr."createdOn" AT TIME ZONE \'+00:00:00\', \'yyyy-MON-dd\') as "createdOn" '

...或类似的东西(不确定语法,因为我没有使用oracleMobile数据库。