Layui解决table日期的格式化问题

很多时候后端传回来的日期数据,和我们看到的数据都是有差别的,例如后端传回来的json数据
当然可以选择在后端格式化后再传回前端,显然我们不推荐你这样做,因为你很难确定,你格式化后的日期格式在所有地方都适用

Layui解决日期格式问题

在table数据日期栏加上: templet: "

{{layui.util.toDateString(d.sbj_start, ‘yyyy-MM-dd HH:mm:ss’)}}即可
上代码

table.render({
					elem: '#test'
					, url: 'http://localhost:8080/item'
					// , url: 'data3.json'
					, toolbar: '#toolbarDemo'
					, title: '用户数据表'
					, totalRow: true 	//开启合计
					, cols: [[
						{ type: 'checkbox', fixed: 'left' }
						, { field: 'id', title: 'ID', width: 100, fixed: 'left', unresize: true, sort: true, totalRowText: '合计' }
						, { field: 'title', title: '标题', width: 200, }
						, { field: 'price', title: '价格', width: 150, }
						, { field: 'sellPoint', title: '卖点', width: 200, }
						, { field: 'num', title: '库存数量', width: 100, sort: true, totalRow: true }
						, { field: 'cid', title: '分类', width: 100 }
						, { field: 'status', title: '状态', width: 100, templet: '#statusTpl' }
						, { field: 'created', title: '创建时间', width: 180, sort: true, templet: "<div>{{layui.util.toDateString(d.created, 'yyyy-MM-dd HH:mm:ss')}}</div>" }
						, { field: 'updated', title: '更新时间', width: 180, sort: true, templet: "<div>{{layui.util.toDateString(d.updated, 'yyyy-MM-dd HH:mm:ss')}}</div>" }
						, { fixed: 'right', title: '操作', toolbar: '#barDemo', width: 150 }
					]]
					, page: true
				});

格式化完成
在这里插入图片描述

注意事项

第一个参数需要和table日期字段对应,不然就是格式化的当前时间
在这里插入图片描述
我的博客即将同步至腾讯云+社区,邀请大家一同入驻:https://cloud.tencent.com/developer/support-plan?invite_code=1rc88r11m0jan

  • 5
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值