layui数据表格时间戳转换为时间格式的方法

时间:2022-07-17 02:27:41
<script id="createTime" type="text/html">
    {{createTime(d.createTime)}} 
    </script>
<script type="text/javascript">
function createTime(v){
	var date = new Date();
    date.setTime(v.time);
    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 M = date.getMinutes();
    M = M<10?("0"+M):M;
    var str = y+"-"+m+"-"+d+" "+h+":"+M;
    return str;
}
</script>

table.render({
		elem: '#LAY_table_user'
		,url:"<%=path%>/mybill/findBill.do"
		,cols: [[
			{field:'type', title: '<spring:message code="mybill.Number"/>', sort: true,align :'center'}
			,{field:'mailno', title: '<spring:message code="mybill.OddOrders"/>',align :'center'}
			,{field:'sex', title: '<spring:message code="mybill.AmountRecharge"/>', sort: true,align :'center'}
			,{field:'playmoney',title: '<spring:message code="mybill.AmountExpenditure"/>',align :'center'}
			,{field:'sign', title: '<spring:message code="mybill.Coupons"/>',align :'center'}
			,{field:'smomey', title: '<spring:message code="mybill.AccountBalance"/>', sort: true,align :'center'}
 			,{field: 'createTime', title: '<spring:message code="mybill.BillingDate"/>', templet: '#createTime'}		
]]
		,id: 'testReload'
		,page: true 
    });

templet:'#createTime'中的#createTime为最上面script的id,d是layui自带的

效果图

layui数据表格时间戳转换为时间格式的方法