Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

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.

Tags:
replied

Hi AbdulSalam,

Will this helpful? JS Bin - Collaborative JavaScript Debugging

Thanks,

KA

0 View this answer in context

Helpful Answer

by
Not what you were looking for? View more on this topic or Ask a question