JS中j将JSON格式装换成Date类型

js中用输出console.log(dd.list[1].createtime)为1378696511000

function jsonDateFormat(jsonDate) {// json日期格式转换为正常格式
try {
var date = new Date(jsonDate);
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() < 10 ? "0" + date.getHours() : date
.getHours();
;
var minutes = date.getMinutes();
if (minutes < 10) {
minutes = "0" + minutes
}
var seconds = date.getSeconds();
var milliseconds = date.getMilliseconds();
return date.getFullYear() + "-" + month + "-" + day + " " + hours + ":"
+ minutes// + "分" + ":" + seconds + "." + milliseconds;
} catch (ex) {
return "时间错误";
}
}
调用方法   console.log(jsonDateFormat(dd.list[1].createtime));
posted @ 2018-08-30 14:31  创作我的创作  阅读(319)  评论(0编辑  收藏  举报