Some tips to show quickly, how to format a Date value from, and to oData. In this example we are using a Hana Cloud database table.
The tables has the following field date, called birthday:
When we execute the method GET in JSON format, we receive in this way:
"id": 1, "name": "Homer", "last_name": "Simpson", "gender": null, "birthday": "/Date(-147398400000)/", "salary": "1500" |
the value “birthday” is the date in milliseconds since Unix Epoch.
http://en.wikipedia.org/wiki/Unix_time
So, if you try to read, or to execute a POST method it won’t work appropriately.
To solve this in XML view, you can use an Input field like below. No special need in the controller to get the data.
<Input id="birthday" value="{path: modelExample>birthday', type: 'sap.ui.model.type.Date', formatOptions: { pattern: 'dd/MM/yyyy', UTC:true } }" /> |
To solve this format problem when you are trying to POST the value, you can use the example below in the javascript function called:
var birthday = new Date(this.getView().byId("birthday").getValue()); // Format value in XML view //valueFormat="yyyy/MM/dd" newEntry.birthday = birthday; |
Date format to oData – Post and Get