Sample code to parse JSON Date Format
Views (398)
Hi,
Just sharing a sample code to parse JSON Date Format (e.g. “\/Date(628318530718)\/”) to Date.
entity = JSON.parse(retrieveReq.responseText).d; if (entity['BirthDate'] != null) { var jdate = parseJsonDate(entity['BirthDate']); var year = jdate.getFullYear(); var month = jdate.getMonth() + 1 < 10 ? '0' + (jdate.getMonth() + 1) : (jdate.getMonth() + 1); var date = jdate.getDate() < 10 ? '0' + jdate.getDate() : jdate.getDate(); var dateString = month + '/' + date + '/' + year; alert(dateString); } function parseJsonDate(jsonDate) { var offset = new Date().getTimezoneOffset() * 60000; var parts = /\/Date\((-?\d+)([+-]\d{2})?(\d{2})?.*/.exec(jsonDate); if (parts[2] == undefined) parts[2] = 0; if (parts[3] == undefined) parts[3] = 0; return new Date(+parts[1] + offset + parts[2] * 3600000 + parts[3] * 60000); } }
Bye.
Filed under: CRM, CRM 2011, oData Tagged: CRM 2011, Microsoft Dynamics CRM, oData

This was originally posted here.
*This post is locked for comments