排名
6
文章
6
粉丝
16
评论
8
{{item.articleTitle}}
{{item.blogName}} : {{item.content}}
ICP备案 :渝ICP备18016597号-1
网站信息:2018-2025TNBLOG.NET
技术交流:群号656732739
联系我们:contact@tnblog.net
公网安备:
50010702506256
50010702506256
欢迎加群交流技术
分类:
前端
可以先尝试这样写:
{field: 'showtime',title: '时间',templet:"<div>{{layui.util.toDateString(d.showtime, 'yyyy-MM-dd HH:mm:ss')}}</div> "但是这样写很有可能出现:layui时间格式化 NaN-NaN-NaN
这一个时候可以使用自定义函数来解决,返回一个你处理后的时间即可
{ field: 'CreateDateTime', title: '时间', templet: function (data) { return 你处理后的时间 } }这个函数有个参数,这个参数随便取名字即可,可以返回这一行的数据,使用这个参数点出来即可,比如要取这个时间就是data.CreateDateTime
处里时间的方法:
可以先把/Date(1567138282927)/ 这种格式的时间转化成日期类型,然后在格式
化成日期类型:
new Date(parseInt('/Date(1567138282927)/'.substr(6, 13)));然后在格式化成指定的日期:
方法可以参考:https://www.tnblog.net/hb/article/details/3676
具体实现:
, {
field: 'CreateDateTime', title: '时间', templet: function (data) {
var day = new Date(parseInt(data.CreateDateTime.substr(6, 13)))
var time = day.format("yyyy-MM-dd hh:mm");
return time;
}
}其中格式化的方法:
/**
*对Date的扩展,将 Date 转化为指定格式的String
*月(M)、日(d)、小时(h)、分(m)、秒(s)、季度(q) 可以用 1-2 个占位符,
*年(y)可以用 1-4 个占位符,毫秒(S)只能用 1 个占位符(是 1-3 位的数字)
*例子:
*(new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423
*(new Date()).Format("yyyy-M-d h:m:s.S") ==> 2006-7-2 8:9:4.18
*/
Date.prototype.format = function (fmt) {
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;
}欢迎加群讨论技术,1群:677373950(满了,可以加,但通过不了),2群:656732739。有需要软件开发,或者学习软件技术的朋友可以和我联系~(Q:815170684)
评价