art template日期格式化

2021-08-26 14:45:59 字數 1423 閱讀 9789

使用art-template我們避免了n多的字串拼接,但遇到日期格式化該如何處理呢?

我們定義乙個處理日期格式化的js函式,放到乙個單獨的檔案dateformate.js。

/**

* 對日期進行格式化,

* @param date 要格式化的日期

* @param format 進行格式化的模式字串

* 支援的模式字母有:

* y:年,

* m:年中的月份(1-12),

* d:月份中的天(1-31),

* h:小時(0-23),

* m:分(0-59),

* s:秒(0-59),

* s:毫秒(0-999),

* q:季度(1-4)

* @return string

* @author yanis.wang

* @see

*/function

dateformat

(date, format) ;

format = format.replace(/([ymdhmsqs])+/g, function

(all, t)

return v;

}else

if(t === 'y')

return all;

});return format;

};

使用:

// art-template日期格式化

template.defaults.imports.dateformat = dateformat;

在頁面先定義模板html

id="mqmonitorrecordtemplate"

type="text/html">

} }td>

}td>

<%=#dateformat(item['createtime'],'yyyy/mm/dd hh:mm')%>

td>

}td>

}td>

tr>

}script>

中先編譯上面的模板

var render = template.compile($('#mqmonitorrecordtemplate').html());
使用(乙個分頁的例子):

function

mqmonitorrecordsearch

() ;

$.get('[[$]]/mqmonitor/search/' + pageno,data,function

(r)

else

});}

python 日期 格式轉換 英文 日期格式轉換

一 date型轉字串 filter date date,yyyymm filter date time,hh mm 在控制器中使用必須注入 filter 模組 scope.dt1 new date 控制器中使用 scope.dt2 filter date scope.dt1,yyyy mm dd h...

Oracle日期格式

日期處理完全版 to date格式 day dd number 12 dy abbreviated fri day spelled out friday ddspth spelled out,ordinal twelfth month mm number 03 mon abbreviated mar...

Oracle 日期格式

oracle 獲取當前時間的月份 select extract year from sysdate from dual oracle 日期引數 今天 select to char sysdate,yyyy mm dd from dual 昨天 select to char sysdate 1,yyy...