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;
    },
     
  • 相关阅读:
    Attributes in C#
    asp.net C# 时间格式大全
    UVA 10518 How Many Calls?
    UVA 10303 How Many Trees?
    UVA 991 Safe Salutations
    UVA 10862 Connect the Cable Wires
    UVA 10417 Gift Exchanging
    UVA 10229 Modular Fibonacci
    UVA 10079 Pizza Cutting
    UVA 10334 Ray Through Glasses
  • 原文地址:https://www.cnblogs.com/xintao/p/11104188.html
Copyright © 2011-2022 走看看