Recently in my current project as per requirement of client. I had to Format Microsoft JSON date.
JSON Dates are not dates – they are Strings So I thought of writing this functions for Formatting JSON Date.
Step-1: Write a Function-
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 + 86400000);
};
function JSONDate(){
var reviewdate = parseJsonDate(entity.xrm_Date);
var date = "";
var month = "";
if ((reviewdate.getDate()) < 10) {
date = "0" + reviewdate.getDate();
}
else {
date = reviewdate.getDate();
}
if ((reviewdate.getMonth() + 1) < 10) {
month = "0" + (reviewdate.getMonth() + 1);
}
else {
month = (reviewdate.getMonth() + 1);
}
reviewDate = date + "/" + month + "/" + reviewdate.getFullYear();
bookReviewdate = bookReviewdate+" "+reviewDate;
}
Step-2: Copy and paste this function into your JS file.
Step 3: Click on OK and then Save and Publish.