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

MVC Grid changes datetime values from the server

2 Answers 96 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
David Bailey
Top achievements
Rank 1
David Bailey asked on 27 Jan 2010, 10:49 PM
Hey,
      I have a problem where the browser is changing the date in datetime objects by adding or subtracting the offset to the data when in the grid.  The server is running on UTC but the client browsers are on EST.  The data should always show EST.  How do I fix the data so that it won't manipulate it in the browser.  Do I need to use an OnRowBound or OnDataBinding client event?

2 Answers, 1 is accepted

Sort by
0
David Bailey
Top achievements
Rank 1
answered on 28 Jan 2010, 05:08 AM
What I did to solve this is added an element in the telerik.grid.js to the cultureInfo array item called enusSortableDate and gave it a value of "MM'-'dd'-'yyyy" and then in the standardFormats variable in formatDate method I added the e key to the variable to call the enusSortableDate.  Everything works fine, filters, sorts and returns the expected values,

After 
format = format ? format : "G";  
add the following line:

 

switch (format) { case 'u'case 'e': date.setHours(date.getHours() +   
(date.getTimezoneOffset()/60), 0, 0, 0); break; } 

 

Of course the version you should use is obfuscated but this should help get you on your way if you are trying to take a Universal Coordinated Time and keep it.  This way when the getDate method is called in the d or dd format it will correct the time to UTC, however it will now call it EST or what ever time zone you are in.  The script could have been modified to call getUTCDate instead.  This way if I can revert back to a format that is base and not hassle with changing code in the standardFormats variable array.

 


0
Georgi Krustev
Telerik team
answered on 29 Jan 2010, 12:27 PM
Hello David,

     If I understand the request correctly, the date should be displayed on the client in UTC format. In general,
when the grid is bound using client-side binging, the date is formatted using the browser's time zone. This is the expected behavior.

You can avoid this behavior, if you choose server binding. Thus the date is passed from the server, without any modification.

Let me know if other questions arise.

Greetings,
Georgi Krustev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Grid
Asked by
David Bailey
Top achievements
Rank 1
Answers by
David Bailey
Top achievements
Rank 1
Georgi Krustev
Telerik team
Share this question
or