Problem with timezones in jqGrid

Feb 19, 2013 at 3:52 AM
I get some objects from WCF services. This objects have DateTime property. Then I show this objects in the grid.
I have a problem with time zones.
On my production servers set UTC 0 timezone. On my local PC I have UTC +6. When I enter on site all dates in grid have wrong date/time. They increased by 6 hours. I don't want this because the WCF service return me time in UTC+6.
How to solve it? Thanks.

Why I think the problem in jqGrid? For example, I have object that contain DateTime property with value 15.02.2013 18:02:10. I saw in the debugger and in all places I have this date/time, but jqgrid show me 16.02.2013 00:02:10.
Feb 19, 2013 at 5:58 AM

For starters the import thing here is that the effect you see is the result of client side code (the jqGrid itself, not the helper). It is also hard to say that this behaviour is wrong. The JSON representation of DateTime by .Net built in serializer looks like this:
As you can see there is a timezone information in there. So you are telling jqGrid that you give him dates in UTC + 0 and browser is telling jqGrid that the client wants to see this date as UTC + 6. In that case the result you see is the only logical outcome.

In general there are only two ways to work around your situation:
  • The most proper way is to keep the correct information about the date. If the date is in UTC + 6 timezone than you should always have it like this. To be exact, what you describe is having a "secret" logical assumption and incorrect date handling which is a bad practice.
  • Send to date to the client not as a DateTime object but as a string, and set proper formats for JqGridColumnFormatter SourceFormat/OutputFormat so jqGrid can know that the string you have send is date.
Feb 19, 2013 at 8:46 AM
I changed type to string and set proper formats. All works fine. Thanks for great support.