//转换日期
formatTime(number,format) {
var formateArr = ['Y','M','D','h','m','s'];
var returnArr = [];
var date = new Date(number * 1000);
returnArr.push(date.getFullYear());
returnArr.push(this.formatNumber(date.getMonth() + 1));
returnArr.push(this.formatNumber(date.getDate()));
returnArr.push(this.formatNumber(date.getHours()));
returnArr.push(this.formatNumber(date.getMinutes()));
returnArr.push(this.formatNumber(date.getSeconds()));
for (var i in returnArr)
{
format = format.replace(formateArr[i], returnArr[i]);
}
return format;
},
//数据转化
formatNumber(n) {
n = n.toString();
return n[1] ? n : '0' + n
},
console.log(this.formatTime(1581400800,'Y-M-D h:m:s')) //2020-02-11 14:00:00
时间戳转化为年月日时分秒
最新推荐文章于 2024-03-20 22:26:44 发布