Wcf数据服务返回的Json DateTime是否错误? [英] Is Json DateTime tick returned by wcf data services incorrect?

查看:67
本文介绍了Wcf数据服务返回的Json DateTime是否错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我的WCF数据服务电话返回日期23/3/2011 6:4:55 PM  1300903495000这是不正确的。


所以我在.net中尝试了这个 - > (new DateTime(2011,3,23,18,4,55))。Ticks返回634365002950000000而不是1300903495000。


错误的1300903495000 - >新的DateTime(1300903495000)返回2/1/0001 12:08:10 pm。


经过一番了解后,我意识到要获得正确的日期,我需要这样做:再填5个右边的数字,并从基数1970添加刻度。 


(新的DateTime(1970,1,1,0,0,0,0))。AddTicks((1300903495000 *) 10000));


我的问题是



  •   1300903495000的返回值是否正确?
  • 我的计算是否正确?

解决方案


OData Verbose DateTime的JSON V2格式使用ASP.NET JSON格式表示日期时间。例如,一个描述是:

http:// msdn。 microsoft.com/en-us/library/bb299886.aspx#intro_to_json_topic2
。刻度与.NET DateTime类中的刻度不同。我认为上面的公式是正确的。


请注意,如果您强制使用OData V3,JSON格式将开始使用DateTime的ISO格式(与XML / ATOM中使用的格式相同)。这可以通过确保您的服务器支持V3然后使用MinDataServiceVersion从客户端发送您的请求来完成:
3.0标头 - 这将强制服务器回复V3响应。


谢谢,


Hi,

my WCF data services call returning date 23/3/2011 6:4:55 PM as 1300903495000 which is incorrect.

so i tried this in .net -> (new DateTime(2011,3,23,18,4,55)).Ticks returns 634365002950000000 and not 1300903495000.

the incorrect 1300903495000 -> new DateTime(1300903495000) returns 2/1/0001 12:08:10 pm.

After some understanding, i realize that to get the correct date i need to do this: pad 5 more digits to the right and add tick from the base 1970. 

(new DateTime(1970, 1, 1, 0, 0, 0, 0)).AddTicks((1300903495000 * 10000));

My questions are

  • Is the returned value of 1300903495000 correct?
  • Is my calculation correct?

解决方案

Hi,

OData Verbose JSON V2 format for DateTime uses the ASP.NET JSON format for date time. One description is for example here: http://msdn.microsoft.com/en-us/library/bb299886.aspx#intro_to_json_topic2. The ticks are not the same as the ticks in the .NET DateTime class. I think your formula above is correct.

Note that if you enforce OData V3 the JSON format will start using the ISO format for DateTime (same as the one used in XML/ATOM). This can be done by making sure your server supports V3 and then send your request from the client with MinDataServiceVersion: 3.0 header - that will force the server to reply with V3 response.

Thanks,


这篇关于Wcf数据服务返回的Json DateTime是否错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆