element ui格式化表格里面的時間


element ui格式化表格里面的時間

原文鏈接:https://blog.csdn.net/weixin_43503080/article/details/106136068

1.安裝monet.js庫

npm install moment --save

2.全局引入

import moment from 'moment';

3.method:定義函數進行時間的格式化

    //過濾秒:格式化時間
    leaveTime(value)
    {
      return moment(value).format('YYYY-MM-DD HH:mm');
    },

4.格式element中的時間字段

        <el-table-column label="創建時間" prop="CreatedAt">
          <template v-slot="scope">
            {{leaveTime(scope.row.CreatedAt)}}
          </template>
        </el-table-column>
      </el-table>

附錄其他使用代碼

// 短時間
export const shortTime = function (value) {
    return moment(value).format('YYYY-MM-DD');
}

// 長時間
export const time = function (value) {
    return moment(value).format('YYYY-MM-DD HH:mm:ss');
}

//過濾秒
export const leaveTime = function (value) {
    return moment(value).format('YYYY-MM-DD HH:mm');
}

// 年月
export const monthTime = function (value) {
    return moment(value).format('YYYY-MM');
}

// 時分秒
export const secondsTime = function (value) {
    return moment(value).format('HH:mm:ss');
}

// 中國標准時間的轉化
export const filterTime = (time, type = 'short') => {
    if (type == 'short') {
        return moment(time).format('YYYY-MM-DD')
    } else {
        return moment(time).format('YYYY-MM-DD HH:mm:ss')
    }
}

export const startOfDate = function(d, dateType = 'day'){
    return moment(d).startOf(dateType)
}

export const endOfDate = function(d, dateType = 'day'){
    return moment(d).endOf(dateType)
}

// 當月第一天和最后一天   傳入一個日期,返回數組['2019-12-01','2019-12-31']
export const lastDateofMonth = function (d) {
    let firstDate = moment(d).startOf('month').format('YYYY-MM-DD');
    let endDate = moment(d).endOf('month').format('YYYY-MM-DD');
    let Datearr = [];
    Datearr.push(firstDate);
    Datearr.push(endDate);
    return Datearr;
}




免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM