您好,欢迎来到榕意旅游网。
搜索
您的当前位置:首页处理后端返回时间戳除以1000后的值。前端显示转换且不影响给后端传值准确性。

处理后端返回时间戳除以1000后的值。前端显示转换且不影响给后端传值准确性。

来源:榕意旅游网
    // 时间戳转时间
    formatTime = (timestamp) => {
    if (timestamp) {
        const tempTimestamp = (timestamp.toString().length === 13) ? timestamp : timestamp*1000
        const time = new Date(tempTimestamp)
        const y = time.getFullYear(); //getFullYear方法以四位数字返回年份
        const M = time.getMonth() + 1; // getMonth方法从 Date 对象返回月份 (0 ~ 11),返回结果需要手动加一
        const d = time.getDate(); // getDate方法从 Date 对象返回一个月中的某一天 (1 ~ 31)
        const h = time.getHours(); // getHours方法返回 Date 对象的小时 (0 ~ 23)
        const m = time.getMinutes(); // getMinutes方法返回 Date 对象的分钟 (0 ~ 59)
        const s = time.getSeconds(); // getSeconds方法返回 Date 对象的秒数 (0 ~ 59)
        // return y + '-' + M + '-' + d;
        return y + '-' + M + '-' + d + ' ' + h + ':' + m + ':' + s;
      } else {
          return '';
      }
    }

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- nryq.cn 版权所有 赣ICP备2024042798号-6

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务