JS 10位、13位时间戳转日期

1.废话不多说,代码直接拿走:(详情链接:https://blog.csdn.net/qq_33026699/article/details/89639816)

 
(注意:下面的date可以加个判断是10位时间戳还是13位时间戳来进行编码是否需要*1000 param为你要转换的时间戳变量
    if(param.length == 10){
        let date = new Date(parseInt(param) * 1000);
    }else if(param.length == 13){
         let date = new Date(parseInt(param));
    }
 )
 
   

 


let date = new Date(parseInt(res.data.rows[i].time) * 1000);
let y = date.getFullYear(); 
let m = date.getMonth() + 1; 
m = m < 10 ? ('0' + m) : m;
let d = date.getDate(); 
d = d < 10 ? ('0' + d) : d;
let h = date.getHours();
h = h < 10 ? ('0' + h) : h;
let minute = date.getMinutes(); 
let second = date.getSeconds(); 
minute = minute < 10 ? ('0' + minute) : minute; second = second < 10 ? ('0' + second) : second; 
// console.log( y + '-' + m + '-' + d + ' ' + ' ' + h + ':' + minute + ':' + second) 
let dates = y + '-' + m + '-' + d + ' ' + ' ' + h + ':' + minute + ':' + second;

 

转载于:https://www.cnblogs.com/xintao/p/11104188.html

你可能感兴趣的:(JS 10位、13位时间戳转日期)