cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

In UI5 planning calendar appointments date is showing one day before

0 Kudos
396

HI Team,

I am Working on one requirement, but here in sap ui5 planning calendar control appointment is showing one day before.

Please let me know how to resolve this error.

Regards,

Preeti

Accepted Solutions (0)

Answers (1)

Answers (1)

Farooq
Product and Topic Expert
Product and Topic Expert

Hello preeti_anandkar,

The SAPUI5 Planning Calendar showing appointments one day before is usually due to timezone differences.

Here's the simple fix:

  1. Backend: Ideally, store all appointment dates and times in UTC (Universal Coordinated Time).
  2. SAPUI5: Use "sap.ui.core.format.DateFormat" in your formatter to convert the UTC time to the user's local timezone before displaying it in the "PlanningCalendar".

API Reference: https://sapui5.hana.ondemand.com/sdk/#/api/sap.ui.core.format.DateFormat

Formatter Sample:

sap.ui.define([
    "sap/ui/core/format/DateFormat"
], function (DateFormat) {
    "use strict";

    return {
        formatUTCDateToLocal: function (oUTCDate) {
            if (!oUTCDate) {
                return null;
            }
            var oDateFormat = DateFormat.getDateTimeInstance({ pattern: "yyyy-MM-dd HH:mm" });
            return oDateFormat.format(oUTCDate);
        }
    };
});

XML Binding:

<PlanningCalendarRow
    startDate="{
        path: 'StartDate',
        formatter: '.formatter.formatUTCDateToLocal'
    }"
    endDate="{
        path: 'EndDate',
        formatter: '.formatter.formatUTCDateToLocal'
    }">
</PlanningCalendarRow>

Regards,
Farooq

ArunJacob
Active Participant
0 Kudos
yes like already mentioned, it is the notorious trouble maker: UTC vs local time, party time is just one day early:)