layui table 时间戳

                , { field: 'CreateTime', width: 175, title: '时间', templet: '<div>{{ laytpl.toDateString(d) }}</div>' },

或者

              , { field: 'CreateTime', width: 175, title: '时间', templet: titleTpl },
<script>
        //时间戳的处理
        var laytpl = function () { };
        laytpl.toDateString = function (d, format) {
            if (d) {
                 var time = d.CreateTime.match(/[^\(\)]+(?=\))/)[0];
            }
            time = timestampToTime(time);
            var date = new Date(time || new Date())
            , ymd = [
              this.digit(date.getFullYear(), 4)
              , this.digit(date.getMonth() + 1)
              , this.digit(date.getDate())
            ]
            , hms = [
              this.digit(date.getHours())
              , this.digit(date.getMinutes())
              , this.digit(date.getSeconds())
            ];

            format = format || 'yyyy-MM-dd HH:mm:ss';

            return format.replace(/yyyy/g, ymd[0])
            .replace(/MM/g, ymd[1])
            .replace(/dd/g, ymd[2])
            .replace(/HH/g, hms[0])
            .replace(/mm/g, hms[1])
            .replace(/ss/g, hms[2]);
        };

        //数字前置补零
        laytpl.digit = function (num, length, end) {
            var str = '';
            num = String(num);
            length = length || 2;
            for (var i = num.length; i < length; i++) {
                str += '0';
            }
            return num < Math.pow(10, length) ? str + (num | 0) : num;
        };

    </script>

    @*<script type="text/html" id="titleTpl">
            {{#
        var date = new Date();
        date.setTime(d.createTime); //NAN 这里没有小写的createTime
        return d.createTime;
    }}
        </script>
        <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), //季度
                    "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;
            }
        </script>*@
    <script id="createTime" type="text/html">
        {{createTime(d.createTime)}}
    </script>
    <script type="text/javascript">
        function timestampToTime(timestamp) {
            var date = new Date(timestamp * 1);//时间戳为10位需*1000,时间戳为13位的话不需乘1000
            Y = date.getFullYear() + '-';
            M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
            D = date.getDate() + ' ';
            h = date.getHours() + ':';
            m = date.getMinutes() + ':';
            s = date.getSeconds();
            return Y + M + D + h + m + s;
        }
    </script>

 

 

 that_obj.startTime = (new Date).getTime();

 

posted @ 2018-06-27 08:45  enych  阅读(572)  评论(0编辑  收藏  举报