ajax返回json数据,对其中日期的解析

JS 对其格式化 方法如下

function ChangeDateFormat(d){
//将时间戳转为int类型,构造Date类型
var date = new Date(parseInt(d.time,10));

//月份得+1,且只有个位数时在前面+0
var month = date.getMonth() + 1 < 10 ?"0" + (date.getMonth() + 1) : date.getMonth() + 1;

//日期为个位数时在前面+0
var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();

//getFullYear得到4位数的年份 ,返回一串字符串
return date.getFullYear()+"-" +month +"-" +currentDate;
}

 

posted @ 2016-12-20 10:29  Crawford  阅读(2830)  评论(0编辑  收藏  举报