GibboK
GibboK

Reputation: 73938

How to convert Format for Date and Time in Sencha Touch?

In Sencha Touch 2 I have a model with the following fields, DateTimeStart if rendered in a List it shows in this format

Mon Feb 11 2013 11:55:00 GMT +100 (W. Europe Standard Time)

I need to create another field (DateTimeStartConverted) based on DateTimeStart I need to convert such date in a more short format using 'Y-m-d'.

Printing the result of DateTimeStartConverted in my conversion method it does not display any result (no errors has been throw).

Any idea how to fix it?

{
   name: 'DateTimeStart',
   type: 'date',
   dateFormat: 'MS'
}, {
   name: 'DateTimeStartConverted',
   type: 'date',
   convert: function(value, record){
       var jsonDate  = record.get('DateTimeStart'); 
       return  Ext.Date.format(jsonDate, 'Y-m-d');
   }
}

Upvotes: 3

Views: 5268

Answers (1)

Jordan Kasper
Jordan Kasper

Reputation: 13273

If you just need to display the date properly in a list item template, then you can use the :date() function within your template:

{
  xtype: 'list',
  ...
  itemTpl: '<p>Date display test - {DateTimeStart:date("m/d/Y")}</p>',
  ...
}

As for your convert function, it looks sound, but what do you get for the value and record arguments? Knowing those values would help a lot.

Upvotes: 6

Related Questions