Layui Table格式化日期(表格)
原始时间是从数据库中获取到的 格式是 /Date(1572490889017)/这种类型的 { title: '生成时间', field: 'SEND_DATE',templet:'<div>{{ FormDate(d.SEND_DATE, "yyyy-MM-dd HH:mm:ss") }}</div>', width: 130 } 然后需要写个js方法格式化就好 //日期: /Date(157
·
原始时间是从数据库中获取到的 格式是 /Date(1572490889017)/ 这种类型的
{ title: '生成时间', field: 'SEND_DATE',templet:'<div>{{ FormDate(d.SEND_DATE, "yyyy-MM-dd HH:mm:ss") }}</div>', width: 130 }
然后需要写个js方法格式化就好
//日期: /Date(1572490889017)/
//日期格式化方法
function FormDate(str, fmt) { //str: 日期字符串;fmt:格式类型
if (str == null || str == '') {
return "";
}
var date = eval('new ' + str.substr(1, str.length - 2)); //截取字符串之后:Date(1572490889017)
var o = {
"M+": date.getMonth() + 1, //月份
"d+": date.getDate(), //日
"H+": date.getHours(), //小时
"m+": date.getMinutes(), //分
"s+": date.getSeconds(), //秒
"q+": Math.floor((date.getMonth() + 3) / 3), //季度
"S": date.getMilliseconds() //毫秒
};
if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (date.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;
}
更多推荐
已为社区贡献2条内容
所有评论(0)