vue.js项目中时间戳转时间最简单方法

 【还需优化,后期改进了继续更新】

timestampToTime(timestamp) {
        var date = new Date(timestamp * 1000);//时间戳为10位需*1000,时间戳为13位的话不需乘1000
        // let Y = date.getFullYear() + '-';
        // let M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
        // let D = date.getDate() + ' ';
        // let h = date.getHours() + ':';
        // let m = date.getMinutes() + ':';
        // let s = date.getSeconds();
        // return Y+this.padLeftZero(M)+this.padLeftZero(D)+this.padLeftZero(h)+this.padLeftZero(m)+this.padLeftZero(s);
        let y = date.getFullYear();
        let MM = date.getMonth() + 1;
        MM = MM < 10 ? ('0' + MM) : MM;
        let d = date.getDate();
        d = d < 10 ? ('0' + d) : d;
        let h = date.getHours();
        h = h < 10 ? ('0' + h) : h;
        let m = date.getMinutes();
        m = m < 10 ? ('0' + m) : m;
        let s = date.getSeconds();
        s = s < 10 ? ('0' + s) : s;
        return y + '-' + MM + '-' + d + ' ' + h + ':' + m + ':' + s;
    }

html 中

<span class="t_red">{{timestampToTime(ProaiAllData.statewritedate)}}</span>

json 数据及 效果图   

{"msg":"操作成功","code":"0","data":{"result":[{"nowwritedate":"1557238891","statewritedate":"1557489600","facebook":"http://www.baidu.com","banner":"https://www.binmark.io/icon/bt.png","team":"百度","people":"0","endwritedate":"1557518400","teitter":"http://www.baidu.com","pdf":"http://www.baidu.com","getnumber":"0.0000","web":"http://www.baidu.com","whitebook":"http://www.baidu.com","name":"百度","reddit":"http://www.baidu.com","usdtnumber":"30000000.0000","logo":"https://www.binmark.io/icon/bt.png","id":"3","state":"0","teaminfo":"百度","teamlogo":"https://www.binmark.io/icon/bt.png","coin":"BD","info":"百度百度百度百度百度百度百度百度百度百度百度百度百度百度百度百度百度百度百度百度百度百度百度百度百度百度百度百度百度"}]}}

Logo

前往低代码交流专区

更多推荐