Results 1 to 5 of 5

Thread: date format in template is not working

Hybrid View

Previous Post Previous Post   Next Post Next Post
    Success! Looks like we've fixed this one. According to our records the fix was applied for TOUCH-1205 in a recent build.
  1. #1
    Sencha User
    Join Date
    Nov 2011
    Posts
    52
    Vote Rating
    1
      0  

    Default date format in template is not working

    Hi,

    I'm trying to format a date inside of a template:

    Code:
    {timestamp:date("d.m.Y")}
    The timestamp field is defined as follows in the model:

    Code:
    {name: 'timestamp', type: 'date', dateFormat: 'c'},
    Unfortunatly the date is not shown if i try to use the :date(format) function. Any ideas or is this a bug?

  2. #2
    Sencha - Sencha Touch Dev Team rdougan's Avatar
    Join Date
    Oct 2008
    Posts
    1,159
    Vote Rating
    7
      0  

    Default

    The following code works for me:

    Code:
    Ext.setup({
        onReady: function()  {
            //defgine my model with the timestamp field
            Ext.define('Model', {
                extend: 'Ext.data.Model',
    
                fields: [
                    {name: 'timestamp', type: 'date', dateFormat: 'c'}
                ]
            });
    
            //create a new instance of that model with a fake timestamp
            model = Ext.create('Model', {
                timestamp: '2004-02-12T15:19:21+00:00'
            });
    
            //show it in a new component using tpl + data
            Ext.Viewport.add({
                tpl: 'The timestamp is: {timestamp}',
                data: model.data
            });
        }
    });
    Some points:

    - Check your server is outputting the correct response.
    - Ensure your model has the proper value
    Sencha Inc.
    Robert Dougan - @rdougan
    Sencha Touch 2 and Ext JS 4 Core Team Member, SASS/Theming Wizard.

  3. #3
    Sencha User
    Join Date
    Nov 2011
    Posts
    52
    Vote Rating
    1
      0  

    Default

    Hi,

    this is also working for me. Please try to add a date format inside of the template.
    Try the following code:

    Code:
            Ext.Viewport.add({
                 tpl: 'The timestamp is: {timestamp:date("d.m.Y")}', 
                data: model.data  
           });

  4. #4
    Sencha - Sencha Touch Dev Team rdougan's Avatar
    Join Date
    Oct 2008
    Posts
    1,159
    Vote Rating
    7
      0  

    Default

    Ah, sorry. I misread your post.

    This is a bug. A quick fix is to open sencha-touch-all-debug.js and go to line 15121. You should see a line like this:

    Code:
    return v.dateFormat(format || Ext.util.Format.defaultDateFormat);
    Replace it with this:

    Code:
    return Ext.Date.format(v, format || Ext.util.Format.defaultDateFormat);
    Sencha Inc.
    Robert Dougan - @rdougan
    Sencha Touch 2 and Ext JS 4 Core Team Member, SASS/Theming Wizard.

  5. #5
    Sencha User Jamie Avins's Avatar
    Join Date
    Mar 2007
    Location
    Redwood City, California
    Posts
    3,661
    Vote Rating
    19
      0  

    Default

    Quote Originally Posted by testvogel View Post
    Hi,

    I'm trying to format a date inside of a template:

    Code:
    {timestamp:date("d.m.Y")}
    The timestamp field is defined as follows in the model:

    Code:
    {name: 'timestamp', type: 'date', dateFormat: 'c'},
    Unfortunatly the date is not shown if i try to use the :date(format) function. Any ideas or is this a bug?
    Formatting like this now works in PR4. The Ajax example uses this style.

    Sencha Inc

    Jamie Avins

    @jamieavins

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •