layui实现把数据表格时间戳转换为时间格式的例子

所属分类: 网络编程 / JavaScript 阅读数: 1687
收藏 0 赞 0 分享

如下所示:

<script type="text/javascript">
function createTime(v){
	var date = new Date(v);
 var y = date.getFullYear();
 var m = date.getMonth()+1;
 m = m<10?'0'+m:m;
 var d = date.getDate();
 d = d<10?("0"+d):d;
 var h = date.getHours();
 h = h<10?("0"+h):h;
 var M = date.getMinutes();
 M = M<10?("0"+M):M;
 var str = y+"-"+m+"-"+d+" "+h+":"+M;
 return str;
}
</script>
table.render({
		elem: '#LAY_table_user'
		,url:"<%=path%>/mybill/findBill.do"
		,cols: [[
			{field:'type', title: '<spring:message code="mybill.Number"/>', sort: true,align :'center'}
			,{field:'mailno', title: '<spring:message code="mybill.OddOrders"/>',align :'center'}
			,{field:'sex', title: '<spring:message code="mybill.AmountRecharge"/>', sort: true,align :'center'}
			,{field:'playmoney',title: '<spring:message code="mybill.AmountExpenditure"/>',align :'center'}
			,{field:'sign', title: '<spring:message code="mybill.Coupons"/>',align :'center'}
			,{field:'smomey', title: '<spring:message code="mybill.AccountBalance"/>', sort: true,align :'center'}
 			,{field: 'createTime', title: '<spring:message code="mybill.BillingDate"/>', 
   templet :function (row){
   return createTime(row.createTime);
   } 
   }		
   ]]
		,id: 'testReload'
		,page: true 
 });

方式二:函数转义。自 layui 2.2.5 开始,templet 开始支持函数形式,函数返回一个参数 d,包含接口返回的所有字段和数据。如下所示:

table.render({
 cols: [[
 {field:'title', title: '文章标题', width: 200
 ,templet: function(d){
 return 'ID:'+ d.id +',标题:<span style="color: #c00;">'+ d.title +'</span>'
 }
 }
 ,{field:'id', title:'ID', width:100}
 ]]
}); 

可以好好看看layui table模块

效果图

<script type="text/javascript">
 
/**13位时间戳转换成 年月日 上午 时间 2018-05-23 10:41:08 */
function createTime(v){ 
 return new Date(parseInt(v)).toLocaleString()
}
/**重写toLocaleString方法*/
Date.prototype.toLocaleString = function() {
  var y = this.getFullYear(); 
 var m = this.getMonth()+1; 
 m = m<10?'0'+m:m; 
 var d = this.getDate(); 
 d = d<10?("0"+d):d; 
 var h = this.getHours(); 
 h = h<10?("0"+h):h; 
 var M = this.getMinutes(); 
 M = M<10?("0"+M):M; 
 var S=this.getSeconds();
 S=S<10?("0"+S):S; 
 return y+"-"+m+"-"+d+" "+h+":"+M+":"+S; 
};
</script>

以上这篇layui实现把数据表格时间戳转换为时间格式的例子 就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。

更多精彩内容其他人还在看

jquery实现可拖拽弹出层特效

这篇文章主要介绍了jquery实现可拖拽弹出层特效,代码非常精简,效果非常棒,这里推荐给有需要的小伙伴
收藏 0 赞 0 分享

浅谈 javascript 事件处理

本文向大家简单介绍了javascript的事件处理机制,从事件源,事件操作到事件处理程序都做了简单介绍,并给出了部分示例,这里推荐给大家。
收藏 0 赞 0 分享

jQuery中:reset选择器用法实例

这篇文章主要介绍了jQuery中:reset选择器用法,实例分析了:reset选择器的功能、定义及匹配重置按钮的使用技巧,需要的朋友可以参考下
收藏 0 赞 0 分享

原生javascript实现隔行换色

这篇文章主要介绍了原生javascript实现隔行换色,需要的朋友可以参考下
收藏 0 赞 0 分享

jQuery中:button选择器用法实例

这篇文章主要介绍了jQuery中:button选择器用法,实例分析了:button选择器的功能、定义及选取按钮的使用技巧,需要的朋友可以参考下
收藏 0 赞 0 分享

jQuery中:file选择器用法实例

这篇文章主要介绍了jQuery中:file选择器用法,实例分析了:file选择器的功能、定义及选取类型为file的<input>元素的使用技巧,需要的朋友可以参考下
收藏 0 赞 0 分享

jQuery中:enabled选择器用法实例

这篇文章主要介绍了jQuery中:enabled选择器用法,实例分析了:enabled选择器的功能、定义及选取所有可用元素的使用技巧,需要的朋友可以参考下
收藏 0 赞 0 分享

AngularJS中取消对HTML片段转义的方法例子

这篇文章主要介绍了AngularJS中取消对HTML片段转义的方法例子,在一些需要显示HTML的地方,就要取消AngularJS的转义,本文就介绍了这种方法,需要的朋友可以参考下
收藏 0 赞 0 分享

jQuery中:disabled选择器用法实例

这篇文章主要介绍了jQuery中:disabled选择器用法,实例分析了:disabled选择器功能、定义及选取所有禁用的表单元素的技巧,需要的朋友可以参考下
收藏 0 赞 0 分享

jQuery中:checked选择器用法实例

这篇文章主要介绍了jQuery中:checked选择器用法,实例分析了:checked选择器的功能、定义及选取选中的复选框或单选按钮时的使用技巧,需要的朋友可以参考下
收藏 0 赞 0 分享
查看更多