0

I have free style app where I am using date field inside the XML table. The issue is, if I change date-time zone of my system (I am using Windows 10), it also changes date and time of fields inside my app.

What I want to achieve is, independent of my system timezone, date/time of fields inside my app should remain the same, it should not change with my system timezone.

Has anyone achieved this? Thanks in advance.

enter image description here enter image description here

Code_Tech
  • 775
  • 13
  • 42
  • Use [`moment-timezone`](https://momentjs.com/timezone/) – Suman Kundu Nov 05 '18 at 10:40
  • Cannot use external libraries. Need to solve this using UI5/JavaScript of possible – Code_Tech Nov 05 '18 at 10:44
  • You can try to use UTC methods from Date() object: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date. Check all the getUTCDate(), getUTCDay() etc... – Lukasz Nov 05 '18 at 10:49
  • 1
    You can format your dates with sap.ui.core.DateFormat and set the UTC flag to true, this way all your dates will be consistent with UTC DateTimes. – Daniel Almeida Nov 05 '18 at 11:14

1 Answers1

3

You need to add the type sap.ui.model.type.Date or sap.ui.model.odata.type.DateTime in your data binding and specify format options UTC equals true.

<ObjectListItem 
    number="{ 
         path: 'YourProperty', 
         type: 'sap.ui.model.type.Date',
         formatOptions: {
            pattern: 'dd.MM.yyyy',
            UTC: true
         }
     }"
 />

Reference: How to handle Edm:DateTime form OData interface in SAPUI5 correct?.

Inizio
  • 2,226
  • 15
  • 18
fabiopagoti
  • 1,467
  • 14
  • 31