artTemplate/template.js模板将时间戳格式化为正常的日期
1:引用<script type="text/javascript" src="../js/artTemplate/template.js"></script>
2:在正常渲染中引入方法?| timestamp: 'yyyy-MM-dd hh:mm:ss'
<div>開始時(shí)間<span>{{value.endTime | timestamp: 'yyyy-MM-dd hh:mm:ss'}}</span></div>
3:在script標(biāo)簽中封裝方法timestamp
//template魔板處理后臺(tái)時(shí)間戳轉(zhuǎn)日期方法
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;
});
4:完成
轉(zhuǎn)載于:https://www.cnblogs.com/Fancy1486450630/p/9796966.html
總結(jié)
以上是生活随笔為你收集整理的artTemplate/template.js模板将时间戳格式化为正常的日期的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 晴神算法笔记
- 下一篇: [软件测试airtest软件安装]——填