一佳一

记录像1+1一样简洁的代码

导航

vue 时间格式

Posted on 2021-08-18 18:09  一佳一  阅读(194)  评论(0编辑  收藏  举报

vue里面增加过滤器方法

 filters: {
                formatTimer: 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 + " " ;
                }
            },

然后 绑定时候使用 formatTimer

{{modelData.FDate | formatTimer}}