View Full Version : using dateFormat without conversion

4 Jun 2012, 8:26 PM

I'd like to use the date formatting available in the library, but do not want the returned value to be converted to the clients' local time.

I store date/time in the db in UTC/GMT/Zulu and would like to display that time to the user after formatting out of ISO 8601 format.

any ideas?


5 Jun 2012, 4:07 AM
I don't think ExtJs modifies your your date/time values in any way; all you have to do is tell Ext how you want date/time values formatted. As you mentioned, date/time fields are usually returned from the database in an ISO 8601 format of yyyy-MM-dd hh:mm:ss. Formatting on the client side is up to you.

If you're populating an ExtJs data store, then you must specify the format of the incoming date/time value via the field configuration. In the model below, you use a date format of 'c' to indicate in incoming date data format of ISO 8601:

Ext.define('SomeApp.model.SomeObject', {
extend: 'Ext.data.Model',
fields: [
{name: 'endDate', type: 'date', dateFormat: 'c'}

When it comes to how the date is to be rendered/formatted for display to the client, you set an appropriate renderer, as in the grid column sample below (See Ext.Date docs for all renderer options):

columns: [{
header: 'Date', dataIndex: 'endDate', width: 90, renderer: Ext.util.Format.dateRenderer('m/d/Y H:i:s')

You've probably also noted the parse() (http://docs.sencha.com/ext-js/4-0/#!/api/Ext.Date-method-parse) and format() (http://docs.sencha.com/ext-js/4-0/#!/api/Ext.Date-method-format) functions of the Ext.Date class. These will allow you to do pretty much anything you want with date/time formatting.

6 Jun 2012, 9:43 AM
for some reason, still unknown, my UTC date is being converted to my timezone when rendered.

the json response is in UTC however the date/time that is displayed is in Pacific time.

When I specify a type of string on the model with no date renderer on the column then it shows the UTC time however this is not ideal for many obvious reasons. It is only when I specify a type of date in the model that the date displayed is in the local Timezone.