0

I am currently working on Rest API using Openrasta.

In this i am passing a date in JSON object to server side e.g. "/Date(1316802600000)/" for date (24/09/2011) which is standard format for sending date. But when I am receiving this on server side this date gets decreased by 1 day(23/09/2011). So each time I send a date across it gets decreased by 1.

Please suggest me some solution for this and let me know if I am making some mistake.

prashant
  • 2,181
  • 2
  • 22
  • 37

2 Answers2

1

That doesn't sound quite like a problem that has to do much with OpenRasta. It may well be a JsonhDataContractSerializer issue, either that or one of your machines has timezone information but your code doesn't assign those correctly (say, truncating it or not using DateTimeOffset or whatever other reason).

Please post some of the code from your client, that may help in diagnosing your issue.

SerialSeb
  • 6,701
  • 24
  • 28
  • I am doing formatDate = "\/Date(" + new Date(strDate).getTime() + "+)\/" this to get valid date format for passing through json. But when i tried it using formatDate = "\/Date(" + new Date(strDate).getTime() + "+0530)\/"; i.e. by adding +0530 to it, i got correct date at server side. – prashant Dec 01 '11 at 10:00
1

The JsonDataContractSerializer DateTime parsing can be very frustrating, especially when dealing with timezones. You might want to look at writing your own json codec that wraps the Json.NET serializer. The DateTime parsing is much more robust and can handle a variety of different DateTime formats.

Here is an example: http://gist.github.com/BobReid/8960146#file-gistfile1-cs

Canuck41
  • 11
  • 3
  • Do you have some examples explaining how to do this? Thanks in advance. – prashant Jan 25 '13 at 06:58
  • Here is a Gist if you are still interested. You will have to download JSON.Net separately (NuGet, OpenWrap, manually) https://gist.github.com/BobReid/8960146#file-gistfile1-cs – Canuck41 Feb 12 '14 at 17:22