VUE项目中前端如何自己处理返回的时间戳

 写博客不是为了博眼球 而是为了记笔记

格式为 年-月-日 时:分:秒        2019-10-10 14:27:10

特别要注意后端返回的时间戳单位 此处为处理毫秒   如果是秒 需要将返回结果乘以1000

                   <el-table-column prop="firstTime" label="發現時間">
                        <template slot-scope="scope">
                          <span>{ { scope.row.firstTime | formatDate }}</span>
                        </template>
                    </el-table-column>

    filters: {
       formatDate: function (value) {
        let date = new Date(value);
        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;
       }
    }, 

猜你喜欢

转载自blog.csdn.net/qq_42177730/article/details/102517590