0
点赞
收藏
分享

微信扫一扫

10位、13位时间戳转换成日期格式JS

Aliven888 2022-03-25 阅读 169

10位、13位时间戳转换成日期格式JS

  • 此处parama为我们需要交换的时间变量
  • 10位时间戳需要*1000
  • 13位不需要
let date = new Date(parseInt(param));      // 13位
let date = new Date(parseInt(param) * 1000)    // 10位
var timeStamp = xxxx //这里为当前时间戳
    // 时间戳转换为日期格式
    let date = new Date(parseInt(timeStamp));
    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;
    console.log(dates)
举报

相关推荐

0 条评论