代码如下,复制即用
/**
* @descripttion: 时间戳转换
* @Author:
* @Date: 2021-06-23 22:07:16
* @输出格式:2022-12-04 17:15:53
* @调用方法 timestampToTime(时间错)
*/
function timestampToTime(timestamp) {
var date = new Date(timestamp * 1); //这个是10位数字的转换 如果想要13位数的话需要乘1000
var Y = date.getFullYear() + "-";
var M =
(date.getMonth() + 1 < 10
? "0" + (date.getMonth() + 1)
: date.getMonth() + 1) + "-";
var D = (date.getDate() < 10 ? "0" + date.getDate() : date.getDate()) + " ";
var h = date.getHours() < 10 ? "0" + date.getHours() + ":" : date.getHours() + ":";
var m = date.getMinutes() < 10 ? "0" + date.getMinutes() + ":" : date.getMinutes() + ":";
var s = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
return Y + M + D + h + m + s;
}
// console.log(timestampToTime(1670145353));
module.exports = {
timestampToTime
}