artTemplate/template.js模板將時間戳格式化爲正常的日期

1:引用<script type="text/javascript" src="../js/artTemplate/template.js"></script>javascript

2:在正常渲染中引入方法 | timestamp: 'yyyy-MM-dd hh:mm:ss'java

<div>開始時間<span>{{value.endTime | timestamp: 'yyyy-MM-dd hh:mm:ss'}}</span></div>spa

3:在script標籤中封裝方法timestamporm

//template魔板處理後臺時間戳轉日期方法
template.helper('timestamp', function(value, format) {
var date = new Date(value);
var y = date.getFullYear();
var m = date.getMonth() + 1;
m = m < 10 ? ('0' + m) : m;
var d = date.getDate();
d = d < 10 ? ('0' + d) : d;
var h = date.getHours();
h = h < 10 ? ('0' + h) : h;
var minute = date.getMinutes();
var second = date.getSeconds();
minute = minute < 10 ? ('0' + minute) : minute;
second = second < 10 ? ('0' + second) : second;
return y + '-' + m + '-' + d + ' ' + h + ':' + minute + ':' + second;
});blog

4:完成ip

相關文章
相關標籤/搜索