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; // 将格式化后的字符串输出到前端显示
        }
      },
  • 相关阅读:
    Moving Price and Standard Price
    Partner function解析
    [ABAP] ABAP中定义和呼叫宏
    ABAP
    Words Learning~~(1-3)
    Words Learning~~(1-2)
    Words Learning~~(1-1)
    SQLSERVER如何查看索引缺失
    Material Stock manage T-code
    远程重启
  • 原文地址:https://www.cnblogs.com/chenzeyongjsj/p/8176584.html
Copyright © 2011-2022 走看看