Kendo MVC Time Zone Time Translation

We observe the following problem related to time differences between our MVC application and Kendo DatePicker. The web server runs in UTC + 0. Web clients work in different time zones (UTC + 1, UTC + 3, UTC-5, etc.).

On the web page there is a choice of date for the date (without the time part), where the user selects one day or month. Behind the scenes, the Date is sent on AJAX request using complete Date objects that contain time and time zone information.

We are only interested in the part of the date, no matter what time zone the client is in. When the user selects the date / month, we want to get C # DateTime in the local server.

For example:

User is at UTC + 1 and selects '01 / 07/2013 Actual C # DateTime object is created as '30 / 06/2013 23:00 We expect to get '01 / 07/2013 00:00:00

We are currently using the following setting in Global.asax:

GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.DateTimeZoneHandliig = Newtonsoft.Json.DateTimeZoneHandling.Local; 

Could you advise?

+7
javascript timezone rest asp.net-mvc-3 kendo-ui
source share
1 answer

The problem is that the conversion becomes all connected between JavaScript date and C # DateTime. What I am doing is converting the date to a string before it is sent to the server. To do this, you can connect to the Kendo DataSource parameterMap function.

Using the parameterMap function:

 var ds = new kendo.data.DataSource({ transport: { parameterMap: function(data, type) { if (type === 'create' || type === 'update') { // this changes the date to 'dd/MM/YYYY' format data.date = kendo.toString(data.date, 'd'); } return data; } } }); 

I also set JsonFormatter.SerializerSettings.DateFormatString = "YYYY/dd/MM hh:mm:ss" because JavaScript can convert this to a Date object without error or other inconvenience. I would also recommend changing your DateTimeZoneHandling to UTC . You do not need a time zone offset, do you?

On the server side in your controller, you can use DateTime.Parse() or let the compiler do it implicitly.

0
source share

All Articles