Here is the sample code
First effect:
Jsondateformat (jsondate) {//json date format converted to normal format
try {
var date = new Date (parseint ( Jsondate.replace ("/date", ""). Replace (")/", "");
var month = Date.getmonth () + 1 < 10? "0" + (date.getmonth () + 1): Date.getmonth () + 1;
var day = date.getdate () < 10? "0" + date.getdate (): Date.getdate ();
return date.getfullyear () + "-" + month + "-" + Day;
} catch (ex) {return
"";
}
}
Second effect:
Sometimes seconds
function Jsondateformat (jsondate) {//json date format to normal format
try {
var date = new Date (parseint ( Jsondate.replace ("/date", ""). Replace (")/", "");
var month = Date.getmonth () + 1 < 10? "0" + (date.getmonth () + 1): Date.getmonth () + 1;
var day = date.getdate () < 10? "0" + date.getdate (): Date.getdate ();
var hours = date.gethours ();
var minutes = Date.getminutes ();
var seconds = date.getseconds ();
var milliseconds = Date.getmilliseconds ();
return date.getfullyear () + "-" + month + "-" + Day + "" + Hours + ":" + minutes + ":" + seconds + "." + Milliseconds;
} catch (ex) {return
"";
}
}
Summarize
The above is the entire content that JavaScript formats the JSON date, although the function is very small, but very practical. I hope we can help you with your study.