How to handle json DateTime returned from WCF Data Services (OData)

According to this msdn link, DateTime objects are…

…represented in JSON as “/Date(number
of ticks)/”. The number of ticks is a
positive or negative long value that
indicates the number of ticks
(milliseconds) that have elapsed since
midnight 01 January, 1970 UTC.

So you are correct that .NET assumes, but it’s UTC instead of GMT (though they are similar). There are some good answers here on SO that give more details and also provide methods for parsing the JSON into a usable date on the client.

As far as converting dates from UTC to a specific time zone, on the server you could use the TimeZoneInfo class which has a ConvertTimeFromUtc method. Or you could write a custom converter that inherits from the JavaScriptConverter class. In javascript, there are the UTC and getTimezoneOffset methods that could be used.

Hope this helps and good luck.

Leave a Comment