本人php小白一枚 在volist 或者 foreach渲染模板须要把时间戳转时间的时候 直接就{$v.addtime | date="Y-m-d H:i:s"}php
今天在用ajax渲染模板的时候发现不会用js把时间戳转时间 就百度了一个方法 分享出来你们看吧;ajax
function timest(timestamp) { var date = new Date(timestamp * 1000);//时间戳为10位需*1000,时间戳为13位的话不需乘1000 Y = date.getFullYear() + '-'; M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-'; D = date.getDate() + ' '; h = date.getHours() + ':'; m = (date.getMinutes() < 10 ? '0'+(date.getMinutes()) : date.getMinutes()) + ':'; s = (date.getSeconds() < 10 ? '0'+(date.getSeconds()) : date.getSeconds()); return Y+M+D+h+m+s; }
直接在须要转时间的地方调用就行了 是否是很简单 this
'+ timest(this.addtime) +'