Possible Duplicate:
How to format a JSON date?
I am calling a JSON web service via Javascript, and the StartDate field is /Date(1268524800000)/. How do I convert this to a human readable format?d
Possible Duplicate:
How to format a JSON date?
I am calling a JSON web service via Javascript, and the StartDate field is /Date(1268524800000)/. How do I convert this to a human readable format?d
Try this:
var str = "/Date(1268524800000)/"; var num = parseInt(str.replace(/[^0-9]/g, "")); var date = new Date(num); alert(date); Fiddle: http://jsfiddle.net/dS2hd/
/(\-?\d+)/.test(str) ? new Date(+RegExp.$1) : null;You can either eval() it, or you can extract the number and pass it to a Date constructor.
if (/^\/Date\((-?\d+)\)\/$/.test(val)) { var serial = parseInt(RegExp.$1); val = new Date(serial); } I've seen dates expressed as /Date(1234567890000-0500)/, so a more robust procedure may be called for to handle the UTC offset.