cancel
Showing results for 
Search instead for 
Did you mean: 

Edm.time conversion in UI5

Former Member
0 Kudos

Using a time picker with below code . The Server side of SAP is in EDM.string format as PT13H31M00S .

How is the value to be converted from time picker to required format.


  <DateTimeInput
  type="Time"

id="datepicker"

  placeholder="Enter Time ..."
  class="sapUiSmallMarginBottom" />


controller,js

var dtime = this.getView().byId('datepicker').getValue();

alert(dtime); //1:31 PM


Are there any functions to achieve the same ?



Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

I have put my code here : JS Bin - Collaborative JavaScript Debugging . How can i achieve the conversion ?

former_member182372
Active Contributor

            // Controller definition

          jQuery.sap.require("sap.ui.core.format.DateFormat");

            sap.ui.controller("local.controller", {

             

                  timeFormatter : sap.ui.core.format.DateFormat.getDateInstance({

        pattern : "PThh'H'mm'M'ss'S'"

    }),

           

                Get_time: function(oEvent) {

     

                  var dtime = this.getView().byId('datepicker').getDateValue();

                 

                 

                 

                  debugger;

alert(this.timeFormatter.format(dtime)); //1:31 PM

                 

                  //add seconds to the picker

                  //to be converted to PT13H31M00S

                 

                },

               

            });

Former Member
0 Kudos

Maksim,

Is there something that i am missing to achieve via jsbin.?

JS Bin - Collaborative JavaScript Debugging

former_member182372
Active Contributor
0 Kudos

getDateValue instead of getValue

Answers (3)

Answers (3)

former_member204338
Participant

I know it's an old thread but just wanted to share alternative solution: you could specify type in binding

<TimePicker value="{path: 'ltime', type: 'sap.ui.model.odata.type.Time'}"/>

former_member182372
Active Contributor
0 Kudos

SAPUI5 Explored

dateValue is an Object, try to use that

Former Member
0 Kudos

How can i put it via datevalue ?. I have used display format and value format before but not datevalue.

santhu_gowdaz
Active Contributor
0 Kudos

see the console in this example,

JS Bin - Collaborative JavaScript Debugging

santhu_gowdaz
Active Contributor
0 Kudos
  • var oInsptmTxt = new sap.m.Text({ 
  •   text: { 
  •     path: "Time"
  •    formatter: function(value) { 
  • return value.match(/(\d{2})H(\d{2})M(\d{2})S$/).slice(-3).join(":"); 
  •     } 
  •   } 
  • });

Refer these links,

EDM.Time is not converting in SAPUI5 | SCN

Former Member
0 Kudos

Can you suggest how to achieve similar in XML format ? My code is added above.

santhu_gowdaz
Active Contributor
0 Kudos

<Text text="{path: "Time", formatter:'Util.FormatterTime' }"/>

 

  In your util formatter write this code,

 

  FormatterTime:function(value)

  {

return value.match(/(\d{2})H(\d{2})M(\d{2})S$/).slice(-3).join(":");

}