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>
    
  • 相关阅读:
    Linux-命令-parted
    Linux-磁盘
    Linux-bash需要转意的字符
    Linux-命令-su-sudo-visudo
    Linux-命令-用户登录及日志查询
    Linux-练习-批量创建用户5密码长度
    250W电源带i7+GTX1080?
    ICMP type code 对应表(转)
    U盘FAT32转换NTFS格式
    Maxdos 9.3不能引导系统进入Maxdos
  • 原文地址:https://www.cnblogs.com/haima/p/13194036.html
Copyright © 2011-2022 走看看