qq三国碎玉怎么得:extjs grid时间格式显示问题

来源:百度文库 编辑:偶看新闻 时间:2024/04/27 22:21:33

extjs grid显示问题真够烦人的,我使用 extjs API格式方法进行格式化,失踪显示不正常,在网上折抄了份,挺管用的。供大家学习一下。

第一步定义:

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; 
}

 

第二步:

var cm=new Ext.grid.ColumnModel([
                {header:'编号',dataIndex:'Id'},
                {header:'标题',dataIndex:'Title',id:'Title'},
                {header:'发布日期',dataIndex:'Intime',renderer : function (val) {return new Date(parseInt(val.substring(6, val.length - 2))).format('yyyy-MM-dd')}}
            ]);