数据库是用的mysql,时间字段的类型是datetime。
java实体类中此字段对应的类型,我采用了java.util.Date(java.sql.Timestamp应该是最对应mysql里的datetime类型的)。
前台采用了Ext.grid.Panel 来显示读取的数据,时间显示为long型。
让grid显示的时间为“年月日时分秒”的形式。
store读取数据时 指定数据的格式是long 而不是string或date
创建Ext.grid.ColumnModel时在相应的列加上renderer:
header : '操作时间',
dataIndex : 'createTime',
width : 150,
sortable : true,
renderer : function(value) {
return Ext.util.Format.date(new Date(parseInt(value)),'Y-m-d H:m:s');
}
这样就搞定了,显示的时间格式为“2016-07-20 15:32:09”。