Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Saturday, May 28, 2016 9:54 AM
I am getting date in json format
"/Date(-62135596800000)/"
and i need it in actual date format or in javascript format
var dateString = "/Date(-62135596800000)/".substr(6);
var currentTime = new Date(parseInt(dateString));
var month = currentTime.getMonth() + 1;
var day = currentTime.getDate();
var year = currentTime.getFullYear();
var date = day + "/" + month + "/" + year;
alert(date);
I have searched above code snippet but it's showing wrong result.
All replies (2)
Tuesday, May 31, 2016 6:04 AM âś…Answered
Try this example
function parseJsonDate(jsonDate) {
var fullDate = new Date(parseInt(jsonDate.substr(6)));
var twoDigitMonth = (fullDate.getMonth() + 1) + ""; if (twoDigitMonth.length == 1) twoDigitMonth = "0" + twoDigitMonth;
var twoDigitDate = fullDate.getDate() + ""; if (twoDigitDate.length == 1) twoDigitDate = "0" + twoDigitDate;
var currentDate = twoDigitMonth + "/" + twoDigitDate + "/" + fullDate.getFullYear();
return currentDate;
};
var Date=parseJsonDate("\/Date(-62135596800000)//");
alert(Date);
For more information you can refer following links
http://stackoverflow.com/questions/10286204/the-right-json-date-format
http://stackoverflow.com/questions/206384/how-to-format-a-microsoft-json-date?lq=1
Saturday, May 28, 2016 10:26 AM
Please refer below url, it is already answered in past. Hope it will be helpful,
http://forums.asp.net/t/1651593.aspx?Convert+JSON+Date+1297246301973+to+javascript+date+only
Type below url, it will show the actual source code.
view-source:http://codeasp.net/assets/demos/blogs/convert-net-datetime-to-javascript-date.aspx