Search code examples
javascriptjqueryodata

How can I convert a date from oData to a date in JavaScript?


I've got an oDate source based upon WCF data services. When I browse to it I see dates like:

<d:SignedUp m:type="Edm.DateTime">2001-01-01T00:00:00</d:SignedUp>

When I retrieve this data using jQuery and JSONP and alert out the date, I see:

/Date(978307200000)/

I need to convert this value back to a Date object that I can then format as desired but I can't work out how to do this.


Solution

  • You can also update your service to OData V3 (WCF Data Services 5.0) and from the client request the JSON to be V3 (MinDataServiceVersion header set to 3.0). In the V3 Verbose JSON the date time format has changed from the /Date(...)/ to the typical XSD format which most jscript libraries should be able to read just fine.