Is it possible to force all EJ2 controls to display dates in UTC rather than in the user's local timezone?
We store various dates in our DB that are not timezone specific, e.g. due dates, dates of birth.
e.g. 1 January 2023 will be stored in our DB and returned by our API as:
In the US this will display in a Grid or DatePicker as 31 December 2022 which makes no sense at all.
Applying the user's local timezone makes sense for timestamps but not for dates.
Thanks for contacting Syncfusion support.
By default, the Grid component will automatically convert and display datetime values in the local time zone when using remote data binding. Based on your requirement, you need to show the date value in UTC time without timeZone conversion. You can achieve your requirement by setting serverTimeZoneOffset as zero. You can use the serverTimezoneOffset property to set the time offset value for the required local time zone, which will allow you to display datetime values accordingly.
ej.data.DataUtil.serverTimezoneOffset = 0; // increase or decrease the value for time conversion
If this post is helpful, please consider Accepting it as the solution so that other members can locate it more quickly.
Thanks for getting back to me.
That seems to work for the Grid, however this is an issue with the DatePicker and InPlaceEditor controls as well.
As you can see, if we set the initial value to 2023-01-01T00:00:00Z it displays this as 12/31/22.
How does this make any sense?
This is a date picker NOT a date time picker.
If I pick 1 January I'm picking 1 January irrespective of timezone.
It makes no sense for the DatePicker to apply a timezone offset and shift the date like this.
Is there a way to disable this for the DatePicker (and also the InPlaceEditor in Date mode)?
It seems the only foolproof way to stop the EJ2 controls from applying TZ offsets is to strip the Z from the UTC date on the server before returning it to the client.
That's what I'm doing now and it seems to work perfectly, would be good if there was a way to completely disable timezone offsetting across all EJ2 controls though.
We have branched the datePicker and inPlaceEditor issues as a new forum thread, please follow the below forum link for further updates.
We mark this forum as solved.
If you have any issues related to this forum (182017) please reopen for further assistance.