• 格式化时间


    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>
    
  • 相关阅读:
    自我介绍+软工5问
    团队展示&选题
    团队展示&选题 (白衣天使队)
    结对编程(-java-实现)
    个人项目wc(Java)
    自我介绍+软工五问
    软件工程结课作业
    第四次博客作业-结对项目
    软件工程第三次作业——关于软件质量保障初探
    20194613 自动生成四则运算第一版报告
  • 原文地址:https://www.cnblogs.com/haima/p/13194036.html
Copyright © 2020-2023  润新知