BootStrap Table將時間戳更改為日期格式


一、使用BootStrap Table遇到的問題:

1.MyBatis從數據庫中取出的時間格式如下:2017-12-04 21:43:19.0,時間后面多了一個點零。

2.從BootStrap Table中展示出的時間格式 是 時間戳格式

二、解決方法:

問題1可以忽略,因為修改了問題2之后,問題1自然就解決了。

在JS中添加如下代碼:

 {
    title: '創建時間',
    field: 'cDate',
    align: 'center',
    //獲取日期列的值進行轉換
    formatter: function (value, row, index) {
        return changeDateFormat(value) }
},

新增 changeDataFormat方法:

    //轉換日期格式(時間戳轉換為datetime格式)
    function changeDateFormat(cellval) {
        var dateVal = cellval + "";
        if (cellval != null) {
            var date = new Date(parseInt(dateVal.replace("/Date(", "").replace(")/", ""), 10));
            var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
            var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
            
            var hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
            var minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
            var seconds = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
            
            return date.getFullYear() + "-" + month + "-" + currentDate + " " + hours + ":" + minutes + ":" + seconds;
        }
    }

  


免責聲明!

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



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