首页 > 其他 > 详细

格式化时间

时间:2020-06-26 11:41:52      阅读:86      评论:0      收藏:0      [点我收藏+]

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>

格式化时间

原文:https://www.cnblogs.com/haima/p/13194036.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!