easyui 中edatagrid 時間類型的修改

從oracle中獲取的時間類型不做處理,一般是帶有時分秒的,而我們只需要年月日的時候就可以才用下面的反法來執行(新手上路,用作自己總結,勿噴)

一:比較簡便

formatter:function(value,row,index){

var unixTimestamp = new Date(value);

   return unixTimestamp.toLocaleDateString();},   這樣就可以了。

二:比較麻煩,優點是可以做成一個工具類,從而多次使用

   Date.prototype.format = function(format) {
if (isNaN(this.getMonth())) {
return '';
}
if (!format) {
format = "yyyy-MM-dd hh:mm:ss";
}
var o = {
/* month */
"M+" : this.getMonth() + 1,
/* day */
"d+" : this.getDate(),
/* hour */
"h+" : this.getHours(),
/* minute */
"m+" : this.getMinutes(),
/* second */
"s+" : this.getSeconds(),
/* quarter */
"q+" : Math.floor((this.getMonth() + 3) / 3),
/* millisecond */
"S" : this.getMilliseconds()
};
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;
};    

然後在formatter直接調用,源碼如下:

formatter: function(value,row,index){

                      return  new Date(value).format("yyyy-MM-dd");
}} ,  

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章