<table class="layui-table" id="list" lay-filter="manageEvent"></table>
2、js部分 :接收后台传来的数据
layui.use(['laypage','layer','element','table','form'],function(){ var laypage = layui.laypage; var layer = layui.layer; var element = layui.element; var table = layui.table; var form = layui.form; table.render({ elem: '#list',url: '${path}/manage/selectManageList',//数据接口,page: false,//开启分页 cols: [[ //表头 {field: 'manageId',title: 'ID',sort: true,fixed: 'left',align:"center"},{field: 'phone',title: '手机号码',{field: 'mrtRoleName',title: '身份',{field: 'loginTime',title: '最后登入时间',align:"center",templet: '#loginTime'},{field: 'status',title: '状态',templet: '#statusTpl',{field:'status',title:'操作',toolbar: '#barDemo',templet:"#statusEdit",unresize: true,align:"center"} ]] });
3、引进 :
<script type="text/html" id="loginTime"> {{ dateFormat(d.loginTime) }} // d是layui自带的 </script>
/* 时间戳转化开始 */ Date.prototype.format = function (fmt) { //author: meizz var o = { "M+": this.getMonth() + 1,//月份 "d+": this.getDate(),//日 "h+": this.getHours(),//小时 "m+": this.getMinutes(),//分 "s+": this.getSeconds(),//秒 "q+": Math.floor((this.getMonth() + 3) / 3),//q是季度 "S": this.getMilliseconds() //毫秒 }; if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1,(this.getFullYear() + "").substr(4 - RegExp.$1.length)); for (var k in o) if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1,(RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length))); return fmt; } String.prototype.format = function (args) { var result = this; if (arguments.length > 0) { if (arguments.length == 1 && typeof (args) == "loginTime") { for (var key in args) { if (args[key] != undefined) { var reg = new RegExp("({" + key + "})","g"); result = result.replace(reg,args[key]); } } } else { for (var i = 0; i < arguments.length; i++) { if (arguments[i] != undefined) { //var reg = new RegExp("({[" + i + "]})","g");//这个在索引大于9时会有问题 var reg = new RegExp("({)" + i + "(})",arguments[i]); } } } } return result; } function dateFormat(value) { return value ? new Date(value*1000).format("yyyy-MM-dd hh:mm:ss") : ""; }
值得注意的是:value值,毫秒还是秒;我这里的value是毫秒所以乘了1000
/* 时间戳转化结束
原文链接:https://www.f2er.com/js/526261.html