var formatTime = function(number,format) { //转换日期
var formateArr = ['Y','M','D','h','m','s'];
var returnArr = [];
var date = new Date(number * 1000);
returnArr.push(date.getFullYear());
returnArr.push(formatNumber(date.getMonth() + 1));
returnArr.push(formatNumber(date.getDate()));
returnArr.push(formatNumber(date.getHours()));
returnArr.push(formatNumber(date.getMinutes()));
returnArr.push(formatNumber(date.getSeconds()));
for (var i in returnArr)
{
format = format.replace(formateArr[i], returnArr[i]);
}
return format;
}
//数据转化
var formatNumber = function(n) {
n = n.toString();
return n[1] ? n : '0' + n
}
console.log(formatTime(1453564799,'Y年M月D日')); //2016年01月23日
console.log(formatTime(1488481383,'Y/M/D h:m:s')); //2017/03/03 03:03:03