«

Vue中两种日期过滤模式

yang 发布于 阅读:377 Vue2阶段


第一种: 年/月/日

//全局的日期过滤器
Vue.filter("formater", function (d) {
    let d1 = new Date(d);
    return d1.getFullYear() + "/" + (d1.getMonth() + 1) + "/" + d1.getDate();
});

第二种: 年/月/日 时/分/秒

// 全局日期时间过滤器
Vue.filter("datetime", (d) => {
    let d1 = new Date(d);
    let year = d1.getFullYear();
    let month = ("0" + (d1.getMonth() + 1)).slice(-2);
    let day = ("0" + d1.getDate()).slice(-2);
    let hour = ("0" + d1.getHours()).slice(-2);
    let minute = ("0" + d1.getMinutes()).slice(-2);
    let second = ("0" + d1.getSeconds()).slice(-2);

    // 格式化输出
    return (
        year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second
    );
});

Vue中两种日期过滤模式

版权所有:微4e
文章标题:Vue中两种日期过滤模式
除非注明,文章均为 微4e 原创,请勿用于任何商业用途,禁止转载

推荐阅读:


扫描二维码,在手机上阅读
请先 登录 再评论