View Full Version : Ext.Date.toString and timezones

4 Nov 2011, 5:31 AM
This is 4.0.7. Had a quick search but couldn't see anything. Why is it that Ext.Date.toString() doesn't use getTimezoneOffset for its output? Or rather why does it have the format it has?

aDate.toString() -> "Fri Nov 04 2011 20:23:13 GMT+0700" <- has timezone
Ext.Date.toString(aDate) -> "2011-11-04T20:23:13" <- has no timezone

Mostly just curious.

My problem is that I want the server to receive UTC dates (or convert on the server with timezone), so I'd need to do something like implement a custom writer which handles dates differently to the usual method (because the model.save()->proxy->writer->serialisation uses Ext.Date.toString() before making the request).


4 Nov 2011, 7:23 AM
You can use Ext.Date.format to do what you want:

Ext.Date.format(date, 'c');

4 Nov 2011, 8:17 AM
I glossed over it, but I have a solution and naturally, yes, I am using .format to get the required result.

I'd just like to know why the timezone information is omitted in toString's implementation. Is it because timezone information in JS Dates cannot be modified (e.g. following option 3 here http://corneliusweiss.de/2008/10/14/dealing-with-time-zones-in-javascript/ )?

27 Nov 2012, 6:45 AM
I have the same problem in 4.1.1a. I need to send a date with an specific format to the server...

I send the data by the property extraParams from the Proxy. When a request is called, in the Ext.data.Connection, the setOptions method check if one of the extraParams values is a Date. When its true, it call to Ext.Object.toQueryString(extraParams), where the Date is transform with the Ext.Date.toString() method. This is a problem, because I need to format the Date to UTC String...

There is a method Ext.JSON.encodeDate() wich format dates with the same format of the Ext.Date.toString(), but I can override encodeDate(). Ext.Date.toString() is marked as private in documentation, so I prefer dont touch it.

It could be nice that toQueryString() call internally to Ext.JSON.encodeDate(date).