Kendogrid automatically converting the date to local timezone

2 Answers 1532 Views
Grid Timeline
Sesha
Top achievements
Rank 1
Sesha asked on 15 Jun 2021, 02:03 PM

Hi,

 

I have a date in my database (25/08/2020). When I try to display it in the kendo grid, it is shown as 25/08/2020 (Expected) for me. But some of the users from USA are shown 24/08/2020. After some debugging, I found that the local timezone conversion is done based on the browsers timezone settings. Anyway we can exclude this automatic conversion globally?

 

Option available so far but not suitable:

 

1. Convert the date to string and display. This means I lose all the functions of using date type.

 

2. Have UTC time in both client and server. This is a tedious process as the application is huge and cannot do this change.

2 Answers, 1 is accepted

Sort by
1
Frederic
Top achievements
Rank 1
Veteran
Iron
answered on 04 Feb 2022, 09:14 PM

new answer to an old question...

When you "parse" your string to create a new date object:

new Date("2022-02-04"),
the local timezone is applied, so here in Eastern Standard Time (-4 or -5), that date becomes 2022-02-03 19:00.
The parser seems to consider the string date in UTC, like if it was written "2022-02-04T00:00:00Z"

One solution can be to declare the date object like that:

var splitted = "2022-02-04".split("-")
new Date(splitted[0], splitted[1] - 1, splitted[2]).

0
Nikolay
Telerik team
answered on 18 Jun 2021, 06:22 AM

Hello Sesha,

By default, the Grid creates its date objects on the client immediately after they are received from the server. Based on the current time, the default JavaScript date object automatically adds the time offset. The default behavior is such because the date objects demonstrate the same default behavior and most users expect to see the date in its current timezone.

The best practice in such cases is to keep a DateTime property in a UTC format on both server and client when using a Grid with Ajax binding and editing. Please refer to the following article supplying information on how that can be achieved: 

Note that the DataSource requestEnd event is handled the dates are converted manually in order to be in UTC time. You can use similar logic in your scenario in order to adjust the dates.

Regards,
Nikolay
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
Grid Timeline
Asked by
Sesha
Top achievements
Rank 1
Answers by
Frederic
Top achievements
Rank 1
Veteran
Iron
Nikolay
Telerik team
Share this question
or