从sap.m.DateTimeInput()获取错误的格式化日期值

时间:2016-07-18 13:24:31

标签: sapui5

Openui5 version working on: 1.38.4

 wk_start_ts=new sap.m.DateTimeInput({type:"DateTime", 
                layoutData: new sap.ui.layout.GridData({linebreak: false,span: "L6 M6 S6"}),
                dateValue: new Date(1468845873851),                                                     
                valueFormat: "dd/MM/yyyy HH:mm:ss", 
                visible : true,


        displayFormat: "dd/MM/yyyy HH:mm"}).placeAt("body");

        var oButton1 = new sap.ui.commons.Button({
            text : "Button",
            tooltip : "This is a test tooltip",
            press : function() {alert(wk_start_ts.getValue());}
        });
        oButton1.placeAt("body");

For example :
Expected data bound by default is 18/7/2016 18:56
Expected output is 18/7/2016 18:56
Actual Output : 07/18/2016 6:56 PM

Note:如果我更改了值然后按下按钮,那么我会得到预期的日期值。

这是一个示例bin(https://jsbin.com/doxoro/edit?js,output)。

添加了测试浏览器的屏幕截图,即Google Chrome

enter image description here

1 个答案:

答案 0 :(得分:1)

我调试了一下,它似乎通过为(设置中的属性)子句处理设置。因此,在您的特定片段中,dateValue在任何格式化选项之前处理。我建议将dateValue放在设置对象的末尾:

wk_start_ts=new sap.m.DateTimeInput({type:"DateTime", 
                layoutData: new sap.ui.layout.GridData({linebreak: false,span: "L6 M6 S6"}),
                valueFormat: "dd/MM/yyyy HH:mm:ss", 
                visible : true,


                displayFormat: "dd/MM/yyyy HH:mm",
                dateValue: new Date(1468845873851)                                                     
         }).placeAt("body");

        var oButton1 = new sap.ui.commons.Button({
            text : "Button",
            tooltip : "This is a test tooltip",
            press : function() {alert(wk_start_ts.getValue());}
        });
        oButton1.placeAt("body");