on 11-03-2015 5:21 AM
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Kathik,
My apologies, I missed these statements in your original example.
var jsonDate = oEvent.Date;
jsonDate = jsonDate.match(/\d/g);
jsonDate = jsonDate.join("");
I believe I am doing the same in these statements:
- var value= JSON.stringify(jsonDate);
- value1 = value.substring(7,20);
Is formatting date possible without this conversion?
I viewed this blog - Working with oData Dates and Times and such a conversions wasn't done here. The .parse method of the DateFormat control does the opposite of what we're doing here and I would like to simply use .format when displaying from oData and .parse when writing to oData, this is what was done in the blog I linked but I'm unable to recreate it.
Thank you.
Thank you for clearing this for me. I appreciate it.
I have a follow up question about Time format.
How do I convert XDS duration PT04H32M00S to EDM time (total milliseconds)? It seems only EDM (total ms) time can formatted with the DateFormat control (according to the blog I linked).
Thank you.
Appreciate your question.
This blog will hep you: EDM.Time is not converting in SAPUI5 | SCN
Thanks,
KA
User | Count |
---|---|
88 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.