简体   繁体   English

令人惊讶的是,Json DateTime在WCF服务反序列化后丢失了几秒钟

[英]Amazingly, Json DateTime with seconds lost Seconds after de-serializing on WCF service

I post(using jQuery $.post) the following json DateTime to a WCF service(using C#): 我将以下json DateTime发布(使用jQuery $ .post)到WCF服务(使用C#):

"/Date(1331713200000)/"

On Firebug CommandLine, I test it: 在Firebug CommandLine上,我测试它:

Date(1331713200000)

This is the output: "Wed Mar 14 2012 11:52:06 GMT+0330" 这是输出:“Wed Mar 14 2012 11:52:06 GMT + 0330”

On server side, I've break point on Service Input argument (which is System.DateTime). 在服务器端,我在服务输入参数(即System.DateTime)上断点。 What is received is the posted date time without Seconds! 收到的是没有秒数的发布日期时间!

{3/14/2012 11:50:00 AM}

Did you ever try this? 你试过这个吗? What's wrong? 怎么了?

Either you're using Firebug incorrectly, or it's in error. 要么你错误地使用Firebug,要么是错误的。 Look at your number, which is meant to be the number of milliseconds since the unix epoch. 看看你的号码,这是自unix时代以来的毫秒数。 Let's divide by 1000 so it ends up being the number of seconds : 1331713200 让我们除以1000,结果是秒数 :1331713200

How would that end up with the number "6" at the end in any way, shape or form? 如何以任何方式,形状或形式最终得到数字“6”?

In fact, we can divide that number by 60 and get a whole number... which entirely in line with the value you've seen on the server side. 实际上,我们可以将该数字除以60得到一个整数...这完全符合您在服务器端看到的值。

The value 1331713200000 does represent 2012-03-14T08:20:00Z. 值1331713200000 确实代表2012-03-14T08:20:00Z。

Maybe these posts will help you out: 也许这些帖子会帮助你:

Send JQuery JSON to WCF REST using date 使用date将JQuery JSON发送到WCF REST

http://skysanders.net/subtext/archive/2010/02/18/wcf-to-json-dates-and-back-again.aspx http://skysanders.net/subtext/archive/2010/02/18/wcf-to-json-dates-and-back-again.aspx

The combination of client dates and WCF don't work well together. 客户日期和WCF的组合不能很好地协同工作。

Date(1331713200000) is returning now , the argument is ignored. Date(1331713200000)将返回目前 ,参数将被忽略。 new Date(1331713200000) is what you should be calling. new Date(1331713200000)是你应该打电话的。 As Jon has said - the time you're getting server-side is correct. 正如Jon所说 - 你获得服务器端的时间是正确的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM