Dateformat在Firefox浏览器中不起作用

时间:2017-01-13 05:53:37

标签: sapui5

我从我的REST获得了一个JSON响应,其中包含三个具有相关日期格式的属性,如下所示:

createdAt:2017-01-10T06:43:16.076Z(使用@Temporal(TemporalType.TIMESTAMP)保存在后端:来自其他电话

fromDate:2017-01-16Z(使用@Temporal(TemporalType.Date)保存:带有datepicker的输入字段,用于捕获用户输入的日期

toDate:2017-01-17Z(使用@Temporal(TemporalType.Date)保存:使用datepicker输入字段以捕获用户输入的日期

在我的XMLView中,我使用格式化程序类来显示上述三个日期 2017年1月10日,2017年1月16日和2017年1月17日。

Formater class:

sap.ui.define([

    "sap/ui/core/format/DateFormat"
], function(constants, DateFormat) {
    "use strict";

    var _parse = function(v) {
        var oDateFormat = DateFormat.getDateTimeInstance({
            pattern: "dd-MMM-YYYY"
        });
        var oDateTimeFormat = DateFormat.getDateTimeInstance({
            pattern: "dd-MMM-YYYY HH:mm:ss"
        });
        return oDateFormat.parse(v) || oDateTimeFormat.parse(v) || new Date(v);
    };

    var _getFormattedDateTime = function(v, patt) {
        if (!v) {
            return v;
        }

        var oDateFormat = DateFormat.getDateTimeInstance({
            pattern: patt
        });
        return oDateFormat.format(_parse(v));
    };

Return {
Date: function(v) {
            return _getFormattedDateTime(v, constants.DateFormat);
        },

DateTime: function(v) {
            return _getFormattedDateTime(v, constants.DateTimeFormat);
        },
}

我在视图元素的xml视图中调用相同的内容:

for createdAt field:

<Text text="{path:'list>embHeaderData/createdAt', formatter:'.formatter.Date'}" tooltip="{path:'list>embHeader/createdAt', formatter:'.formatter.DateTime'}"/>


for fromDate field:

<Text text="{path:'list> embProcessData /fromDate', formatter:'.formatter.Date'}" tooltip="{path:'list> embProcessData /fromDate', formatter:'.formatter.DateTime'}"/>


for toDate field:

<Text text="{path:'list> embProcessData /toDate', formatter:'.formatter.Date'}" tooltip="{path:'list>embProcessData/toDate', formatter:'.formatter.DateTime'}"/>

三种日期格式在chrome中工作正常但是当我看到相同的xml视图时,fromDate和toDate在firefox中是空白的。

请帮助我在Firefox浏览器中纠正此问题。

2 个答案:

答案 0 :(得分:2)

您可以使用标准数据类型及其丰富的配置功能,而不是编写自己的格式化程序:

{{1}}

答案 1 :(得分:0)

  1. 请删除绑定路径中的fromdate和toDate的空格。
  2. 请使用这样的日期格式(假设所有时间都是UTC):

    var oDateFormat = sap.ui.core.format.DateFormat.getDateTimeInstance({
        pattern: "yyyy-MM-ddZ",
        UTC: true
    });
    var oDateFormatter = sap.ui.core.format.DateFormat.getDateTimeInstance({
        style: "medium",
        UTC: true
    });
    // example:
    oDateFormatter.format(oDateFormat.parse("2017-01-17Z"), true);
    

    解析toDate和fromDate。 错误是因为

    new Date("2017-01-17Z")
    

    在Firefox中不起作用,但在Chrome中不起作用。

相关问题