将时间戳转换为时间格式
方法一:
var getTime = new Date(dataList[i].createTime); //从后台获取过来的时间戳
Date.prototype.toLocaleString = function() {
var date = new Date(getTime); //时间戳为10位需*1000,时间戳为13位的话不需乘1000
Y = date.getFullYear() + \’/\’;
M = (date.getMonth() + 1 < 10 ? \’0\’ + (date.getMonth() + 1) : date.getMonth() + 1) + \’/\’;
D = date.getDate() < 10 ? \’0\’ + date.getDate() : date.getDate() + \’ \’;
H = date.getHours() < 10 ? \’0\’ + date.getHours() : date.getHours() + \’ \’;
MI = date.getMinutes() < 10 ? \’0\’ + date.getMinutes() : date.getMinutes() + \’ \’;
S = date.getSeconds() < 10 ? \’0\’ + date.getSeconds() : date.getSeconds() + \’ \’;
return Y + M + D + “ ” + H + “:” + MI + “:” + S;
};
formatTime = getTime.toLocaleString();
方法二:
var formatTime = disposeDate(dataList[i].createTime); //将后台获取来的时间戳整理为时间格式 封装时间格式的函数 function disposeDate(dateTime) { var getTime = new Date(dateTime); dateTime = getTime.toLocaleString(); return dateTime; }