easyui表格里的時間戳轉換成日期格式


1.第一步 寫以下方法來格式化日期

Date.prototype.format = function (format) {  
    var o = {  
        "M+": this.getMonth() + 1, // month  
        "d+": this.getDate(), // day  
        "h+": this.getHours(), // hour  
        "m+": this.getMinutes(), // minute  
        "s+": this.getSeconds(), // second  
        "q+": Math.floor((this.getMonth() + 3) / 3), // quarter  
        "S": this.getMilliseconds()  
        // millisecond  
    }  
    if (/(y+)/.test(format))  
        format = format.replace(RegExp.$1, (this.getFullYear() + "")  
            .substr(4 - RegExp.$1.length));  
    for (var k in o)  
        if (new RegExp("(" + k + ")").test(format))  
            format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));  
    return format;  
}  

2.第二步 擴展的Date的format方法(上述插件實現)  

function formatDatebox(value) {  

    if (value == null || value == '') {  
        return '';  
    }  
    var dt;  
    if (value instanceof Date) {  
        dt = value;  
    } else {  
        dt = new Date(value);  
    }  
  
    return dt.format("yyyy-MM-dd"); 

3.第三部  寫好那就用唄 下面綠色的代碼

$('#dg').datagrid({
    url:'../RampAcLimitFltAction/getAcLimitFltList2.do',
   columns:[[ 

           {field:'limitStart',title:'起始時間',width:100,align:'center',formatter: formatDatebox}, 
           {field:'limitEnd',title:'結束時間',width:100,align:'center',formatter: formatDatebox}

             ]]

 


免責聲明!

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



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