前端vue过滤器转换时间格式方式

        <el-table :data="tableData" style="width: 100%" height="100%" border>
          <el-table-column prop="sbks" label="科室" align="center">
          </el-table-column>
          <el-table-column prop="status" label="提交状态" sortable align="center">
            <template slot-scope="scope">
              <span v-if="scope.row.status=='2'" style="color: rgb(1 210 20);font-weight: 800;">已提交</span>
              <span v-else-if="scope.row.status=='1'" style="color: red;font-weight: 800;">未提交</span>
            </template>
          </el-table-column>
          <!-- <el-table-column prop="submit_date" label="提交时间" sortable align="center">
          </el-table-column> -->
          <el-table-column label="提交时间" sortable align="center">
            <template slot-scope="scope">
              <span>{{scope.row.submit_date|formatDate}}</span>
            </template>
          </el-table-column>

          <el-table-column label="操作" align="center">
            <template slot-scope="scope">
              <el-button @click.native.prevent="showXq(scope.$index, tableData)" type="text" size="small">
                查看详情
              </el-button>
            </template>
          </el-table-column>

 方式一:

 //过滤器
    filters: {
 //过滤时间为年-月-日 hh:mm:ss
      formatDate: function (oldDate) {
        debugger
        // 方式1 转换为'yyyy-MM-dd HH:mm:ss'
        function add0(num) { return num < 10 ? '0' + num : num } // 个位数的值在前面补0
        const date = new Date(oldDate)
        const Y = date.getFullYear()
        const M = date.getMonth() + 1
        const D = date.getDate()
        const h = date.getHours()
        const m = date.getMinutes()
        const s = date.getSeconds()

        const dateString = Y + '-' + add0(M) + '-' + add0(D) + '  ' + add0(h) + ':' + add0(m) + ':' + add0(s)
        return dateString

        // 方式2 转换为'yyyy/MM/dd HH:mm:ss'
        // return new Date(oldDate).toLocaleString()
      },
   //过滤器
    filters: {
      //过滤时间为年-月-日 hh:mm:ss
      formatDate: function (timestamp) {
        debugger
        if (timestamp) {
          var date = new Date(parseInt(timestamp));//时间戳为10位需*1000,时间戳为13位的话不需乘1000
          let Y = date.getFullYear() + '-';
          let M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
          let D = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate()) + ' ';
          let h = (date.getHours() < 10 ? '0' + (date.getHours()) : date.getHours()) + ':';
          let m = (date.getMinutes() < 10 ? '0' + (date.getMinutes()) : date.getMinutes()) + ':';
          let s = (date.getSeconds() < 10 ? '0' + (date.getSeconds()) : date.getSeconds());
          return Y + M + D + h + m + s;
        } else {
          return "";
        }
      }
      
    },

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值