View Full Version : timestamp timezone problem

12 Aug 2009, 3:29 AM
I have problem with conversion of mysql timestamp into date format. In other timezone users see other date.
I use in reader: {name:'upload_ts',type:'date',dateFormat:'timestamp'}
and the formfield:
{xtype:'datefield',width:100, fieldLabel:'Uploaded', name:'upload_ts', format:'d.m.Y', allowBlank:false, readOnly:false, style:'padding:0px'}

If users open the page in different timezones, they see other date in the formfield. How can I solve this? I have one fixed timestamp and I want to see the same formated date in every timezone.

Thanks for your help!

12 Aug 2009, 4:46 AM
Instead of dateFormat:'timestamp' use dateFormat:'c' and let your server send the date as '1999-03-14T20:24:32Z'.

12 Aug 2009, 4:49 AM
Thanks for your answer. There is no other solution? I have to change in a lot of ajax files if I decide to send the normal date format instead of the timestamp. Is there any global settings to set which timezone to use? Or something like this...

12 Aug 2009, 5:39 AM
You could convert the date during load, e.g.

{name: 'myfield', type: 'date', convert: function(v){
var d = new Date(v*1000); // assume v = timestamp
return d.add(Date.SECOND, -(d.getTimezoneOffset() + serverOffset) * 60); // correct for timezone
(serverOffset is the timezone offset of the server)