zoukankan      html  css  js  c++  java
  • vue2.0 自定义时间过滤器

    html

    <td>{{serverInfo.serverTime| formatTime('YMDHMS')}}</td>

    js

    serverTime: new Date().getTime(),
    filters: {
        // 时间过滤器
        formatTime: function(value, type) {
          let dataTime = "";
          let data = new Date();
          data.setTime(value);
          let year = data.getFullYear();
          let month = data.getMonth() + 1;
          let day = data.getDate();
          let hour = data.getHours();
          let minute = data.getMinutes();
          let second = data.getSeconds();
        month < 10 ? (month = "0" + month) : month;
        day < 10 ? (month = "0" + day) : day;
        hour < 10 ? (hour = "0" + hour) : hour;
        minute < 10 ? (minute = "0" + minute) : minute;
        second < 10 ? (second = "0" + second) : second;
    if (type == "YMD") {
            dataTime = year + "-" + month + "-" + day;
          } else if (type == "YMDHMS") {
            dataTime =
              year +
              "-" +
              month +
              "-" +
              day +
              "  " +
              hour +
              ":" +
              minute +
              ":" +
              second;
          } else if (type == "HMS") {
            dataTime = hour + ":" + minute + ":" + second;
          } else if (type == "YM") {
            dataTime = year + "-" + month + "-";
          }
          return dataTime; // 将格式化后的字符串输出到前端显示
        }
      },
  • 相关阅读:
    软件测试课堂练习1
    安卓增删改查
    安卓数据库表
    安卓注册登录
    安卓购物清单
    安卓计算器
    第四周安卓作业
    第七周作业
    jsp第六周
    第四次jsp作业
  • 原文地址:https://www.cnblogs.com/chenzeyongjsj/p/8176584.html
Copyright © 2011-2022 走看看