zoukankan      html  css  js  c++  java
  • 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;

    // 封装的时间戳转换日期函数
    dateTrans(date) {
        let _date = new Date(parseInt(date));
        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;

        return dates;
    },
     
  • 相关阅读:
    python 类
    hdu 5761 Rowe Bo 微分方程
    calendar 示例
    hdu 5753 Permutation Bo
    hdu 5752 Sqrt Bo
    finally 语句
    throws 和 throw
    python打开.pkl的文件并显示里面的内容
    Python 类变量,成员变量,静态变量,局部变量
    python 实例方法,类方法,静态方法,普通函数
  • 原文地址:https://www.cnblogs.com/xintao/p/11104188.html
Copyright © 2011-2022 走看看