LayUI把表格中的時(shí)間戳改成格式化的時(shí)間

通過(guò)返回的json 格式數(shù)據(jù),時(shí)間是用時(shí)間戳表示的,如以下數(shù)據(jù)

json數(shù)據(jù)

可以通過(guò) temple 屬性格式化時(shí)間, 向layui table表頭中添加templet : "<div>{{layui.util.toDateString(d.ordertime, 'yyyy-MM-dd HH:mm:ss')}}</div>",就可以格式化字符串

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>layui表格渲染,時(shí)間問(wèn)題</title>
  <link rel="stylesheet" href="./css/layui.css" media="all">
  <script src="./js/layui.all.js"></script>
  <style type="text/css">
    body{overflow-y: scroll;}
  </style>
</head>
<body>
 
<table id="demo" lay-filter="test"></table>
 
 
<script>
layui.use('table', function(){
  var table = layui.table;
  
  //第一個(gè)實(shí)例
  table.render({
    elem: '#demo'
    ,height: 315
    ,url: 'http://localhost:8080/springmvc09_LayuiTable/getCar.action' //數(shù)據(jù)接口
    ,page: true //開(kāi)啟分頁(yè)
    ,cols: [[ //表頭
      {field: 'id', title: 'ID', sort: true, fixed: 'left'}
      ,{field: 'name', title: '用戶(hù)名'}
      ,{field: 'pwd', title: '性別'}
      ,{field: 'date', title: '注冊(cè)時(shí)間', templet : "<div>{{layui.util.toDateString(d.ordertime, 'yyyy年MM月dd日 HH:mm:ss')}}</div>"}
    ]]
  });
});
</script>
</body>
</html>

效果:


image.png

yyyy年MM月dd日 可以根據(jù)需要改。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀(guān)點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容