javascript - Working with Dates in Sapui5 -


how can current date, current year, current month, , current week in sapui5? code started with:

var otype = new sap.ui.model.type.date(); otype = new sap.ui.model.type.date({ source: {}, pattern: "mm/dd/yyyy" }); 

i have no idea go here. appreciated.

edit: how following javascript function sapui5 table?

function addzero(i) {     if (i < 10) {         = "0" + i;     }     return i; }  function datefunction() {     var today = new date();     var dd = addzero(today.getdate());     var mm = addzero(today.getmonth() + 1);     var yyyy = today.getfullyear();     var hours = addzero(today.gethours());     var min = addzero(today.getminutes());     var sec = addzero(today.getseconds());     var ampm = hours >= 12 ? 'pm' : 'am';     hours = hours % 12;     hours = hours ? hours : 12; // hour '0' should '12'      today = mm + '/' + dd + '/' + yyyy + "  " + hours + ":" + min + ":" + sec + " " + ampm; } 

to current date:

there no predefined function in sapui5, hence use native javascript method:

var odate = new date();  

how put date in table?

js fiddle

var odata = {     results: [{         name: "today",         date: new date()     }, {         name: "someday",         date: new date("2015/01/01")     }, {         name: "new year",         date: new date("2016/01/01")     }] }  var omodel = new sap.ui.model.json.jsonmodel(odata);   // create table: var otable = new sap.m.table({     columns: [     new sap.m.column({         header: new sap.m.label({             text: "when"         })     }),     new sap.m.column({         header: new sap.m.label({             text: "date"         })     })] }); var otype = new sap.ui.model.type.date({     pattern: "mm/dd/yyyy" }); var otemplate = new sap.m.columnlistitem({     cells: [     new sap.m.text({         text: "{name}"     }),     new sap.m.text({         text: {             path: 'date',             type: otype         }     })] });  otable.setmodel(omodel); otable.binditems("/results", otemplate); otable.placeat("content"); 

update: based on comment request need this:

 var otype = new sap.ui.model.type.date({         pattern: "mm/dd/yyyy"     }); otable.addcolumn(new sap.ui.table.column("today", {     label: new sap.m.label({         text: {             path: 'today',             type: otype         }     })     sortproperty: 'today',     filterproperty: 'today' })); 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -