Wednesday, August 13, 2014

Parse Json Date to Date Object

Parse jsondate in JavaScript to a Date Object:
Below are two methods I use  
Method 1:
var jsonDate = "/Date(1224043200000)/"
var value = new Date(parseInt(jsonDate.substr(6)));

Method 2:
var jsonDate = "/Date(1224043200000)/"
var value = new Date(parseInt(jsonDate.replace(/(^.*\()|([+-].*$)/g, '')));
if you want in "mm/dd/yyyy" format, use this along with the above script
var dat = value.getMonth()+ 1 + "/" + value.getDate()+ "/" +value.getFullYear();