cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

UI5 Date Formatting

adnanmaqbool
Contributor
0 Likes
4,266

Hi All

I have a date field on XML view and its showing date format correctly , when i am picking date using date calendar.

However , when i am placing same date by using Odata from backend system, its showing complete date with time and zone.

Listed below is XML View and Controller codes:

Controller , is showing date as "Thu Mar 01 2018 05:00:00 GMT+0500 (Pakistan Standard Time)" whereas I want to show in format 01.03.2018

<Label text="Date of Joining" required="true"/>
<DatePicker name="Zdoj" value="{path: 'Zdoj', type: 'sap.ui.model.type.Date', formatOptions: {pattern: 'dd.MM.yyyy', strictParsing: true , UTC: true}}" id="Zdoj_id"
enabled="{= ${viewModel>/mode} === 'edit'? false: true}" visible="true"/>
var oDate = new sap.ui.model.type.Date({source: {}, pattern: "dd.MM.yyyy"});			
oDate = oData.Zdoj;
that.getView().byId("Zdoj_id").setValue(oDate);

Accepted Solutions (1)

Accepted Solutions (1)

adnanmaqbool
Contributor
0 Likes

Able to resolve the issue , using the following code in controller of view. Closing the thread.

var dateFormat = sap.ui.core.format.DateFormat.getDateInstance({pattern :"dd.MM.yyyy"});
           var oDate = dateFormat.format(oData.Zdoj);

 that.getView().byId("Zdoj_id").setValue(oDate);

Answers (0)