VUE时间戳转换原创

原创
小哥 5个月前 (02-08) 阅读数 50 #大杂烩

VUE时间戳转换,src引言的方式

1.通过 vue过滤器 -在创作中 Vue 实例之前全局定义的筛选器vue.filter

index.html

{{time | timeStamp}}

style.js

Vue.filter(timeStamp, function (value) {
    if (!value) return ---
    //时间戳转换
        var date = new Date(value * 1000);//时间戳为10位需*1000,时间戳为13位字不需要相乘1000
        Y = date.getFullYear() + -;
        M = (date.getMonth() + 1 < 10 ? 0 + (date.getMonth() + 1) : date.getMonth() + 1) + -;
        D = (date.getDate() < 10 ? 0 + date.getDate() : date.getDate()) +  ;
        h = (date.getHours() < 10 ? 0 + date.getHours() : date.getHours()) + :;
        m = (date.getMinutes() < 10 ? 0 + date.getMinutes() : date.getMinutes()) + :;
        s = date.getSeconds() < 10 ? 0 + date.getSeconds() : date.getSeconds();
        return Y + M + D + h + m + s;
})
版权声明

所有资源都来源于爬虫采集,如有侵权请联系我们,我们将立即删除