指定日期时间格式WCF数据服务 [英] Specify datetime format for WCF Data Service

查看:1025
本文介绍了指定日期时间格式WCF数据服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有指定由WCF数据服务返回DateTime数据的格式的方法?

Is there a way to specify the formatting of DateTime data returned by a WCF data service?

<一个href=\"http://stackoverflow.com/questions/3818719/how-to-handle-json-datetime-returned-from-wcf-data-services-odata\">This问题似乎是说,默认的格式,它看起来像 /日期(1339515455030)/ ,是因为午夜Januery 1,1970年UTC毫秒数。我可以找出如何解析,如果我有,但我宁愿指定一个更友好的格式。

This question seems to say that the default format, which looks like /Date(1339515455030)/, is the number of milliseconds since midnight Januery 1, 1970 UTC. I can figure out how to parse that if I have to but I'd rather specify a more friendly format.

推荐答案

的OData的DateTime格式(假设你还没有格式化它为一个字符串)是依赖于客户端和服务器之间协商的有线格式。上面的格式与 JSON详细并符合标准的JavaScript Date对象。该 Atom格式是不同的,JSON是轻还是不同的。特别说明的是,我们决定从传统JavaScript日期格式移开赞成 ISO 8601的对JSON轻。在任何一种情况下,如果你使用一个客户端,如WCF DS客户端或data.js,客户端将采取适当的反序列化的价值关怀。

The OData DateTime format (assuming you haven't already formatted it out to a string) is dependent on the wire format negotiated between client and server. The format above is from JSON Verbose and corresponds to a standard JavaScript Date object. The Atom format is different, and JSON Light is different still. Of special note is that we decided to move away from the traditional JavaScript Date format in favor of ISO 8601 for JSON Light. In any of these cases, if you're using a client such as the WCF DS client or data.js, the client will take care of deserializing the value properly.


  • 的Atom格式的日期:&LT; D​​:订购日期
    L:TYPE =Edm.DateTime&GT; 1996-07-04T00:00:00&LT; / D:订购日期&GT;

  • JS​​ON格式的详细日期:订购日期:\\ /日期(836438400000)\\ /

  • JS​​ON格式光日期:发货日期:1996-07-16T00:00:00

  • Atom formatted date: <d:OrderDate m:type="Edm.DateTime">1996-07-04T00:00:00</d:OrderDate>
  • JSON verbose formatted date: "OrderDate":"\/Date(836438400000)\/"
  • JSON light formatted date: "ShippedDate":"1996-07-16T00:00:00"

有关各种平台当前的客户端库,在这里看到: http://www.odata.org/libraries

For current client libraries on a variety of platforms, see here: http://www.odata.org/libraries

这篇关于指定日期时间格式WCF数据服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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