Javascript function to convert a json date into more readable format to user.
// Converts a date received in JSON data from the server in format "\Date(1234567890123)\" to a short
// date string in format MM/dd/yyyy.
function ConvertJsonDateString(jsonDate) {
var shortDate = null;
if (jsonDate) {
var regex = /-?\d+/;
var matches = regex.exec(jsonDate);
var dt = new Date(parseInt(matches[0]));
var month = dt.getMonth() + 1;
var monthString = month > 9 ? month : '0' + month;
var day = dt.getDate();
var dayString = day > 9 ? day : '0' + day;
var year = dt.getFullYear();
shortDate = monthString + '/' + dayString + '/' + year;
}
return shortDate;
};
Hey buddy,
ReplyDeletethanks a lot,
its working fine and giving me desire output.
once again thanks
Thanks for your appreciation..
Deletethanks it works perfectly
ReplyDeleteThanks for your appreciation..
DeleteThanks
ReplyDeleteGreat solution! I am required to make a web app work in IE9 and this is the only json to mm/dd/yyyy formatter that works for IE9 as well as the modern browsers.
ReplyDeleteGreat solution, it works perfectly!!!
ReplyDeleteGreat work!
ReplyDeleteHey excellent job
ReplyDeleteThank you so Much..
ReplyDelete