I use SpringMVC 3.0 to provide data to a ExtJS 4.0 web application.
SpringMVC date fileds are serialized in timestamps 13-digit by default since I use
<mvc:annotation-driven />
with jackson-mapper-lgpl-1.6.3.jar
. I think that the serialization is made by the MappingJackson2HttpMessageConverter
that uses an ObjectMapper
with WRITE_DATES_AS_TIMESTAMPS
set as true by default.
This is good for me, this is a sample record result {"userName":"belan","isactive":"Y","userId":240,"created":1358244995113,"createdby":"dadar"}
In ExtJS I use a Ajax-Json proxy and I define the created field of the user model like this.
Ext.define('Pms.model.User', {
extend : 'Ext.data.Model',
fields : [ ....
{name:'created',type: 'date',, dateFormat: 'timestamp'},
...],
idProperty: 'userId',
proxy : {
type : 'ajax',
api : {
read: 'users/view.action',
...
},
}
My problem is that Extjs converts create the JS Date object considering the timestamp as a 10-digit timestamp instead of a 13-digit time stamp. So I get dates like
22 Mar 40123
since the last three digit are not considered like mills.
The only solution I found is not convert the date in the model but formatting the value after in the grid column renderer:
,{
header: "Created",
width: 170,
flex:1,
dataIndex: 'created',
renderer: function(date){
console.log(date);
return Ext.Date.format((new Date(date)),'d-M-Y');
}
Can someone suggest me a better solution?
According to the list of supported date formats in the documentation, your dateFormat
should be time
for a millisecond timestamp instead of timestamp
for a UNIX timestamp.