Date element in Sharepoint 2010

Jan 11, 2012 at 6:36 PM

If I accessing a date element from a Sharepoint 2010 list I get a string not a date object.

OData.read(requestUri, function (data) {
  for (var i = 0; i < data.results.length; i++) {
    alert(data.results[i].Modified);
    // I got a string: /Date(872467200000)/
  }

Is this correct?

 

Jan 12, 2012 at 1:58 AM
Edited Jan 12, 2012 at 1:59 AM

Hi VolkerMSYS,

   Hope you are doing great.  Yes this is correct... without any metadata the library will not try to parse Date literals in a JSON feed and instead returns them as strings.  You can control this behavior and have the library try and parse these values into Date objects:

  • Globally, meaning that the library will do the parsing for every JSON response received by setting the odata.jsonHandler.recognizeDates flag to true.
  • Per request, by setting the recognizeDates property of the request object to true:
OData.read({ requestUri: "uri", recognizeDates: true} , function (data) {
  for (var i = 0; i < data.results.length; i++) {
    alert(data.results[i].Modified);
    // I got a string: /Date(872467200000)/

Regards,

Alex Trigo.

  

 

Jan 12, 2012 at 12:21 PM

Hi Alex,
now it woks fine,
Thanks

Regards
Volker