开发者

How do I transfer my dates properly from browser to server

开发者 https://www.devze.com 2023-04-01 09:14 出处:网络
I have to situations where I tra开发者_StackOverflownsfer dates from browser to server. 1) First situation is through a jQuery/JSON call to an ASMX service (.NET 4.0).

I have to situations where I tra开发者_StackOverflownsfer dates from browser to server.

1) First situation is through a jQuery/JSON call to an ASMX service (.NET 4.0).

2) The second situation is when page first serializes an object, which includes a date, to a hidden field and then the page is posted to server. The hidden field is parsed (using .NET's built in JavaScriptSerializer).

So, let's say the user enters the date "2011-08-31". In the first situation the resulting date on the server is 2011-08-30 22:00 (because I am currently in a +2 time zone). However, in the second situation the resulting date on the server is 2011-08-31 (correct).

Both situtations use the same JSON serializer on the browser.

But I cannot understand why these two are generating different dates on server :-( Does anyone know?


You need to use UTC dates, take a look at these resources:

get UTC Date in javascript

converting UTC with C#

0

精彩评论

暂无评论...
验证码 换一张
取 消