We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Force all EJ2 controls to display dates in UTC time zone

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:

2023-01-01T00:00:00Z

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.


4 Replies

PS Pavithra Subramaniyam Syncfusion Team April 27, 2023 05:27 AM UTC

Hi Rob,


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.serverTimezoneOffset0// increase or decrease the value for time conversion

 


Regards,

Pavithra S

If this post is helpful, please consider Accepting it as the solution so that other members can locate it more quickly.





RO Rob April 27, 2023 09:59 AM UTC

Hi Pavithra,


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.


See below:


https://stackblitz.com/edit/4mmvbb?file=index.ts


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)?


Thanks,


Rob



RO Rob April 27, 2023 10:56 AM UTC

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.



PS Pavithra Subramaniyam Syncfusion Team May 2, 2023 11:48 AM UTC

Rob,

We have branched the datePicker and inPlaceEditor issues as a new forum thread, please follow the below forum link for further updates. 


https://www.syncfusion.com/forums/182106/force-all-ej2-controls-to-display-dates-in-utc-time-zone-branched-from-f182017  


We mark this forum as solved. 


If you have any issues related to this forum (182017) please reopen for further assistance.


Loader.
Live Chat Icon For mobile
Up arrow icon