SAPUI5 Formatting best Practice

Victor Ho
SAPUI5 best pratices
1 min readJan 18, 2019

Hi,

Even SAPUI5 team has already documented things you need to know about formatting when using SAPUI5. But I believe that’s not enough for us as a developer working in enterprises environment, where you need to work with multiple formats for data that are different across different countries & culture.

That’s why I wrote this post to keep some best practice that’s not documented clearly in the SAPUI5 document.

Date format: Be aware that the “format string” is case-sensitive

That’s it. When coming to date format, please remember that dd.mm.yyyy is different from dd.mm.YYYY

The outcome of 2 below variables (sFromatedDate & sFromatedDate2) are different:

var oDate = new Date(2018,11,31);
var sFromatedDate = sap.ui.core.format.DateFormat.getDateInstance({
pattern: "dd.MM.YYYY"
}).format(oDate);
// sFromatedDate == 31.12.2019
var sFromatedDate2 = sap.ui.core.format.DateFormat.getDateInstance({
pattern: "dd.MM.yyyy"
}).format(oDate);.

// sFromatedDate == 31.12.2018

If you want more details about the reason behind this difference, check out this GitHub issue:

sap.ui.model.. Different between oModel.setData(oData) and oModel.setProperty(sPath, oData)

Both can be used to set Data to Model.

But setData() is used to set the whole data set to model.

setProperty is used to:

  • set data to one specific path in the model.
  • Trigger the change on UI that is bound to the property of model.

--

--

Victor Ho
SAPUI5 best pratices

Utilize technology to help people have better life.