开发者

Send javascript date to webservice

I've a .NET webse开发者_高级运维rvice which takes an integer and a date object has a parameter. I'm calling the webservice using AJAX with jQuery, but I'm having trouble sending the date in the correct format.

When a .NET webservice returns a date object, it is in the UTC format (milliseconds since 1/1/1970), so I figured I should use the same format when sending a date from the client to the webservice, but when I do (eg. that value Date(1308787200000)), then I get an error from the webservice saying that it "is not a valid value for DateTime".

What am I missing here?

Regards, Steffen


When you serialize a javascript date object to json it converts to date(time_since_epoch) so that it can easily be converted back with javascript.

.NET on the other hand likes a different format for dates... and that format is dependent on the localization of the machine. Usually this is "mm/dd/yyyy hh:mm:ssAM" in the local timezone of the windows machine.

Your best bet is to either convert this date to a string on the javascript side or to parse the date on the .NET side.

on the .NET side you can convert using the following to convert the string (once again dependent on the local time of the server):

 DateTime.Parse


Use this: var now = new Date().toISOString();

It will give you the right format (i.e. 2014-02-23T20:16:26:298Z)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜