This is a migrated thread and some comments may be shown as answers.

How to stop time zone conversion when cell enters edit mode

1 Answer 150 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ben
Top achievements
Rank 1
Ben asked on 10 Jan 2019, 09:52 PM

Hi all,

I currently have a grid that contains a datetime column that we use to display just the time. When retrieving the time data, we're parsing it with code as follows before the data is being returned to the grid:

var tz = System.TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time");
schedule.StartTimeDT = System.TimeZoneInfo.ConvertTimeToUtc(DateTime.Parse(schedule.StartTime), tz);

 

In the grid definition the column is set up as such:

columns.Bound(c => c.StartTimeDT).Title("Start Time").HtmlAttributes(new { style = "text-align: center;" })

 

When viewed in from a computer that's not in the EST zone, the time value gets automatically changed to whatever the computer timezone is. We got around to forcing it to display EST in the view mode of the grid by modifying the column definition to use a client template:

columns.Bound(c => c.StartTimeDT).Title("Start Time").HtmlAttributes(new { style = "text-align: center;" }).EditorTemplateName("_TimePicker1").ClientTemplate("\\#= moment(data.StartTimeDT).tz('America/New_York').format('HH:mm') \\#");

 

Which works fine in view mode. But once I click on the edit button to go into the inline edit mode, the time is being changed again. How do I stop this automatic time zone shift when in edit mode?

1 Answer, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 11 Jan 2019, 07:11 AM
Hi Ben,

I am sharing the answer from the support ticket that you have opened with the same question:

"When a Date object is created on client-side it is using the client's time zone, which is what you are describing. Note that this is not related with the Grid in particular, but it is rather a standard WEB application problems with different server and client-side time zones. In order to unify the time I could suggest the following HowTo example:
https://docs.telerik.com/aspnet-mvc/helpers/grid/how-to/editing/utc-time-on-both-server-and-client"

If further questions arise, I would suggest that we continue the communication in the support thread.


Regards,
Konstantin Dikov
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Grid
Asked by
Ben
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Share this question
or