How is the date of the layui data table formatted like 2012-12-30?

clipboard.png


< html lang= "en" xmlns:th= " http://www.thymeleaf.org";>

<meta charset="UTF-8">
<title>test</title>
<link rel="stylesheet" th:href="@{"/webjars/layui/2.2.6/css/layui.css"}">
<script language="JavaScript" th:src="@{"/webjars/jquery/3.3.1/dist/jquery.min.js"}"></script>
<script language="JavaScript" th:src="@{"/js/dateformat.js"}" charset="utf-8"></script>

< / head >
< body >
< ul class= "layui-nav" lay-filter= "" >

<li class="layui-nav-item layui-this">
    
</li>
<li class="layui-nav-item">
    <a href="javascript:;"></a>
    <!--  -->
    <dl class="layui-nav-child">
        <dd><a th:href="@{""}"></a></dd>
        <dd><a th:href="@{""}"></a></dd>
    </dl>
</li>

<li class="layui-nav-item layui-col-lg-offset8"><a th:href="@{""}"></a></li>
<li class="layui-nav-item"><a th:href="@{""}"></a></li>

< table id= "stu" > < / table > < script type= "text/html" id= "barDemo" > View Edit Delete < / script > < script th:inline= "none" > $(function () { Layui.use ("table", function () { Var $table = layui.table; / / first instance $table.render ({ Elem:"- sharpstu", Height: 300, / / data interface, Url:"/ stu/student/getAllClazz", / / Open paging Page: true, / / Meter header Cols: [[ {checkbox: true}, {field: "sid", title:" student number, width: 200, sort: true}, {field: "name", title:" name, edit: "text", width: 100, {field: "birth", title:" date of birth, type: "date", templet:"- sharpbirth"}, {field: "gender", title:" gender, width: 60}, {field: "idCard", title:" provincial certificate number"}, {field: "address", title:" home address"}, {field: "clazz.cid", title:" Class number", templet: "- sharpcid"}, {field: "right", title:" operation, width: 177, toolbar: "- sharpbarDemo"} ]], }); $table.on ("checkbox (stu)", function (obj) { Console.log (obj); }); $table.on ("edit (stu)", function (obj) { / / obj.value: gets the modified value, obj.data: gets all the key values of the row, and obj.field: gets the field Var value = obj.value, data = obj.data, field = obj.field; The layer.msg ("[ID:"+ data.id +"]"+ field + "field is changed to:" + value); }); $table.on ("tool (stu)", function (obj) { Console.log (obj); }); }) }); < / script > < script th:inline= "javascript" type= "text/html" id= "birth" > {{- sharp Var birth = function (birth) { If (date) { Var t = new Date (birth); Return t.getFullYear () + "-" + (t.getMonth () + 1) + "-" + t.getDate (); } else { Return ""; } } }} {{birth (d.birth)}} < / script > < script th:inline= "javascript" type= "text/html" id= "cid" > {{- sharp Return d.clazz.clazzName; }} < / script > < / body > < script language= "JavaScript" th:src= "@ {"/ webjars/layui/2.2.6/layui.all.js"}" charset= "utf-8" > < / script > < / html >
Mar.03,2021

clipboard.png
change the one in the picture to the following, and you can format the date.

< script th:inline= "javascript" type= "text/html" id= "birth" >

{{-sharp
return layui.util.toDateString(d.birth.time, 'yyyy-MM-dd')
}}

< / script >

Menu