cancel
Showing results for 
Search instead for 
Did you mean: 

Time Conversion in SAP UI5

former_member251546
Participant
0 Kudos

Hi,

Good morning All,

I am getting the Flight data from Odata service. Up to here Its fine.

Departure time and Arrival time fields are getting time values  but i would like see the time format like 7.50pm or 7.50am.

As of now  I am getting the values as below as :

Departure time      Arrival Time

PT09H00M00S     PT17H21M00S

How to convert the Time format .Please let me know.

Accepted Solutions (1)

Accepted Solutions (1)

Qualiture
Active Contributor
0 Kudos

former_member251546
Participant
0 Kudos

Hi

Thank you Robin.

Answers (2)

Answers (2)

SergioG_TX
Active Contributor
0 Kudos

make sure you are mapping the right column and then also, make sure you take care of any offset time depending on your timezone

sivakumar_mobility
Active Participant
0 Kudos

Hi,

In controller add below code and call that function in your view.

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

Date : function (value) {

  if (value) {

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

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

  } else {

  return value;

  }

  },

I hope above code will help you.

with regards,

siva.

former_member251546
Participant
0 Kudos

Hi,

Thank you very much Siva.

Let me try it.

sivakumar_mobility
Active Participant
0 Kudos

Hi,

Definitely it will work. If any issue let me know.

with regards,

siva.

former_member251546
Participant
0 Kudos

Hi Siva,

I am  writing the code in Index file only.  Here must i write the function under template of Departure time  and Arrival time ?? Please assist me.

  //Create an instance of the table control

     var tableo = new sap.ui.table.Table({

      title: "Table with flight",

      visibleRowCount: 7,

      navigationMode: sap.ui.table.NavigationMode.Paginator

     });

        tableo.addColumn(new sap.ui.table.Column({

             label: new sap.ui.commons.Label({text: "Airline ID"}),

             template: new sap.ui.commons.TextField().bindProperty("value", "Airlineid"),

             }));

             tableo.addColumn(new sap.ui.table.Column({

             label: new sap.ui.commons.Label({text: "Connection ID"}),

             template: new sap.ui.commons.TextField().bindProperty("value", "Connectid"),

             }));

            

             tableo.addColumn(new sap.ui.table.Column({

             label: new sap.ui.commons.Label({text: "Airport From"}),

             template: new sap.ui.commons.TextField().bindProperty("value", "Airportfr"),

             }));

            

             tableo.addColumn(new sap.ui.table.Column({

             label: new sap.ui.commons.Label({text: "Airport To"}),

             template: new sap.ui.commons.TextField().bindProperty("value", "Airportto"),

             }));

            

             tableo.addColumn(new sap.ui.table.Column({

             label: new sap.ui.commons.Label({text: "City From"}),

             template: new sap.ui.commons.TextField().bindProperty("value", "Cityfrom"),

             }));

            

             tableo.addColumn(new sap.ui.table.Column({

             label: new sap.ui.commons.Label({text: "City To"}),

             template: new sap.ui.commons.TextField().bindProperty("value", "Cityto"),

             }));

            

             tableo.addColumn(new sap.ui.table.Column({

             label: new sap.ui.commons.Label({text: "Price"}),

             template: new sap.ui.commons.TextField().bindProperty("value", "Price"),

             }));

            

             tableo.addColumn(new sap.ui.table.Column({

             label: new sap.ui.commons.Label({text: "Departure Time"}),

             template: new sap.ui.commons.TextField().bindProperty("value", "Deptime"),

             }));

            

             tableo.addColumn(new sap.ui.table.Column({

             label: new sap.ui.commons.Label({text: "Arrival Time"}),

             template: new sap.ui.commons.TextField().bindProperty("value", "Arrtime"),

             }));

tableo.setModel(modelo);

tableo.bindRows("/FLIGHTSET"); 

tableo.placeAt("content");

sivakumar_mobility
Active Participant
0 Kudos

Hi balaji ,

I was used XML view like this,

<ObjectAttribute

  text="{

  path:'"Deptime',

  formatter:'util.formatter.Date'

  }" />

In above util is folder name which means path.

can you try same in js view also.

with Regards,

siva.