echart table Date Format

Use echart table shows data but provides the background for the time stamp 13, the time stamp is displayed in the table, a time stamp into YYYY-MM-DD HH-MM -SS time format is as follows:
Reference several ways:

element UI-time formatted data table method
vue UI element-converted time stamp the form display
using the element under the form vue transfer date stamp
vue + timestamp conversion table element

Trial and error
method ① * .replace use will be reported in the vue () * method is not a method, it should not be a chain structure is identified, the specific reasons I have yet to find out, there is time to take another look.
② method is useful, but not a standard conversion result, when the number is not zero complement the single digits, with a range of data together will be very beautiful.
③ method using the Moment tool library, import library when I failed many times, unusable moment () method can be used if the case will be very simple.
④ method does not use formatter method element-ui in the table, but to write a single filter, but inside the syntax is not a problem.
The end result
I combine the characteristics of the project and methods method ③ ④ together to achieve a time format, the following codes:

<el-table-column
      prop="checkTime"
      header-align="center"
      label="检测时间"
      show-overflow-tooltip
      width="200"
      align="center"
      :formatter="dateFormat"
></el-table-column>

Note that
this problem is really wrong too many times more than the
earlier method must write colon! ! !
Methods must be written in front of colon! ! !
Methods must be written in front of colon! ! !

The following method of writing in which method:

dateFormat(row, column) {
      var date = new Date(row.checkTime);
      var Y = date.getFullYear() + "-";
      var M =
        (date.getMonth() + 1 < 10
          ? "0" + (date.getMonth() + 1)
          : date.getMonth() + 1) + "-";
      var d =
        date.getDate() < 10
          ? "0" + (date.getDate() + " ")
          : date.getDate() + " ";
      var h =
        date.getHours() < 10
          ? "0" + (date.getHours() + ":")
          : date.getHours() + ":";
      var m =
        date.getMinutes() < 10
          ? "0" + (date.getMinutes() + ":")
          : date.getMinutes() + ":";
      var s =
        date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
      return Y + M + d + h + m + s;
    }

JavaScript Date Object

The performance of the converted
2020-2-12 16:49:28

Published 23 original articles · won praise 0 · Views 367

Guess you like

Origin blog.csdn.net/zhao_66/article/details/104317044