Skip to Content
0
Oct 10, 2013 at 10:04 AM

How to set Date format dynamically?

357 Views

Hi All,

I have a master.view.xml file and code given below

<ObjectAttribute

text="{

path:'WiCdFtd',

formatter:'date9>/dateformatpath'

}" />

i have a json model as like below in application.js file

var uiConfig={dateformatpath:"util.Formatter.Date"};

var oModel9 = new sap.ui.model.json.JSONModel(uiConfig);

//this.getView().setModel(oModel7,"uiConfig");

sap.ui.getCore().setModel(oModel9, "date9");

i have utill > Formatter.js file code a below

Date : function (value) {

if (value) {

var oDateFormat = sap.ui.core.format.DateFormat.getDateTimeInstance({pattern: "MM-dd-yyyy"});

return oDateFormat.format(new Date(value));

} else {

return value;

}

},

Date1 : function (value) {

if (value) {

var oDateFormat = sap.ui.core.format.DateFormat.getDateTimeInstance({pattern: "dd-MM-yyyy"});

return oDateFormat.format(new Date(value));

} else {

return value;

}

}

Thanks in advance

Ravi Varma