zoukankan      html  css  js  c++  java
  • 格式化时间

    main.js里

    import { formatDate , parseTime, resetForm, addDateRange, selectDictLabel, download } from '@/utils/costum'
    
    // 全局方法挂载
    
    Vue.prototype.formatDate = formatDate
    

    costum.js里

    // 日期格式化  time=1551334252272; //定义一个时间戳变量 返回2020-6-20 08:06:50
    export function formatDate(time) {
      if (time.length === 0 || time === 0) {
        return ""
      }
      let d=new Date(time*1000);
      let timeObject = new Date(d);   //创建一个指定的日期对象
      let year = timeObject.getFullYear();  //取得4位数的年份
      let month = timeObject.getMonth() + 1;  //取得日期中的月份,其中0表示1月,11表示12月
      let date = timeObject.getDate();      //返回日期月份中的天数(1到31)
      let hour = timeObject.getHours();     //返回日期中的小时数(0到23)
      let minute = timeObject.getMinutes(); //返回日期中的分钟数(0到59)
      let second = timeObject.getSeconds(); //返回日期中的秒数(0到59)
      return year + "-" + p(month) + "-"+ p(date) + " " + p(hour) + ":" + p(minute) + ":" + p(second);
    }
    
    //创建补0函数
    function p(s) {
      return s < 10 ? '0' + s: s;
    }
    

    .vue模板表格里调用方法

    <el-table-column label="直播结束时间" align="center" prop="liveTimeEnd" :show-overflow-tooltip="true" width="160">
            <template slot-scope="scope">
              <span>{{ formatDate(scope.row.liveTimeEnd) }}</span>
            </template>
    </el-table-column>
    
  • 相关阅读:
    ui5 call view or method from another view
    vuejs helloworld
    vuejs v-model
    vuejs v-bind
    vuejs on
    vuejs fatherandson
    vuejs scope
    vuejs keep-alive
    VLAN虚拟局域网
    网线的制作
  • 原文地址:https://www.cnblogs.com/haima/p/13194036.html
Copyright © 2011-2022 走看看