vue中时间过滤器中的月日不足两位补0

参考文档:https://blog.csdn.net/qq_51075057/article/details/115123324

 

vue中时间过滤器中的月日不足两位补0

先将月,和日转换为字符串,然后用字符串的padStrat(2,0)方法(两位,不足补0)

复制代码
filters: {
    handleData(date) {
      const timeDate = new Date(date);
      const year = timeDate.getFullYear();
      const month = (timeDate.getMonth() + 1).toString().padStart(2, 0);
      const day = timeDate.getDate().toString().padStart(2, 0);
      const hour = timeDate.getHours().toString().padStart(2, 0);
      const min = timeDate.getMinutes().toString().padStart(2, 0);
      const s = timeDate.getSeconds().toString().padStart(2, 0);
      return year + "-" + month + "-" + day + " " + hour + ":" + min + ":" + s;
    },
        },
复制代码

 

posted @   小小仓鼠  阅读(145)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
点击右上角即可分享
微信分享提示