当前位置:Gxlcms > JavaScript > json日期数据转成日期字符串

json日期数据转成日期字符串

时间:2021-07-01 10:21:17 帮助过:11人阅读

function ChangeDateFormat(jsondate) {

jsondate = jsondate.replace("/Date(", "").replace(")/", "");

if (jsondate.indexOf("+") > 0) {

jsondate = jsondate.substring(0, jsondate.indexOf("+"));

} else if (jsondate.indexOf("-") > 0) {

jsondate = jsondate.substring(0, jsondate.indexOf("-"));

}

//alert(jsondate);

var date = new Date(parseInt(jsondate, 10));

//alert(date.getHours());

var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;

var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();


return date.getFullYear() + "-" + month + "-" + currentDate ;


}

人气教程排行