json时间格式(时间戳)转成Extjs日期格式(grid字段的时间)

本文介绍如何在Extjs4.0中处理json时间戳,将其转换为适用于grid字段的日期格式。通过在列模型的renderer函数中使用Ext.util.Format.date方法,将时间戳转换为'Y-m-d'格式的日期。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

当数据库里面用用时间戳(也就是毫秒数)来存储时间后,读取之后,转成json数据格式,存储在这种格式里面的值也还是 毫秒数的形式,在Ext页面所要显示的现在的日期格式,
在表格里面,可以通过renderer 渲染返回到页面用日期格式显示,
JSON格式:var json =[{createTime:'1234567676'}]    ,createTime里面是时间戳。

在列模型里面可以这样子写。。

案例1:

columns: [

{text: "出生日期", width: 100, sortable: true, dataIndex: 'birthDate',renderer:function(value,row){return Ext.util.Format.data(new Data(parseINt(value)),
'Y-m-d')}},
{text: "入院时间", width: 100, sortable: true, dataIndex: 'inputDate',renderer:function(value,row){ return Ext.util.Format.date(new Date(parseInt(value)),
'Y-m-d')}},

]

案例2:

ColumnModle[
{
header : "创建时间",
width : 80,
dataIndex : "createData",
id : "createData",
sortable : true,
renderer : function(value) {
//    alert(value);
if (value == null || value == 0) {
return 'null'
} else {
//时间转好,将时间戳转换成Ext显示的日期格式
return Ext.util.Format.date(new Date(parseInt(value)),
'Y-m-d')
}
}
}]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值