Skip to Content

Issues with sap.ui.core.format.DateFormat

Hello UI5 experts,

I'm a new developer and ran into some problems trying to format a JSON Date object and XDS Duration.

I have an application with an XML view, I call the formatter like so:

<Input id="x" value="{path:'item>/Erzet',formatter:'getDateFormat'}"</Input>

My formatter function looks like so:

function getDateFormat(jsonDate){
if(jsonDate){
var value= JSON.stringify(jsonDate);
value1 = value.substring(7,20);
var oDateFormat = sap.ui.core.format.DateFormat.getDateInstance({pattern: "dd/MM/yyyy"});
var cdate = oDateFormat.format(new Date(Number(value1)));
return cdate;
}return;
}

The above works, but when I use the code I found in UI5's documentation I either get NaN/NaN/0NaN or an error "Uncaught TypeError: d.getDay is not a function". Is there anyway I can format date/time without slicing it? I want to use the .parse method while updating oData.

Snippets of what I've tried:

var oDate = new Date(jsonDate);
var oDateFormat = sap.ui.core.format.DateFormat.getDateInstance({pattern: "dd/MM/yyyy"});
return oDateFormat.format(oDate);
var oDateFormat = sap.ui.core.format.DateFormat.getDateInstance({pattern: "dd/MM/yyyy"});
return oDateFormat.format(new Date(jsonDate));

^ returns - NaN/NaN/0NaN

var oDateFormat = sap.ui.core.format.DateFormat.getDateInstance({pattern: "dd/MM/yyyy"});
return oDateFormat.format(jsonDate);

^ returns  "Uncaught TypeError: d.getDay is not a function"

Could someone help me find out what I'm doing wrong here?

Thank you.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    Nov 03, 2015 at 06:50 AM

    Hi AbdulSalam,

    Will this helpful? JS Bin - Collaborative JavaScript Debugging

    Thanks,

    KA

    Add comment
    10|10000 characters needed characters exceeded