开发者

How to convert Ajax serialized dates to date format in sencha touch

开发者 https://www.devze.com 2023-03-06 23:27 出处:网络
I am building an App using Sencha touch api. I have a 开发者_StackOverflow社区model Ext.regModel(\'Task\',

I am building an App using Sencha touch api. I have a 开发者_StackOverflow社区model

Ext.regModel('Task',
    {fields: [{name:'TaskID', type:'int'}, 
             {name:'DueDate', type:'date'},
             {name:'ClientName', type:'string'},
             {name:'TaskName', type:'string'},
             {name:'AssignedTo', type:'string'}]
});

I recieve a date /Date(1304879400000)/ i.e Ajax serialized date. So how do i convert into readable date format. Any help would be appreciated.

Thanks


Use a converter in the model config:

fields: [
    'id'
    {
        name: 'datetime',
        type: 'date',
        dateFormat: 'MS'
    }

The above model has two fields: id and datetime, with datetime being parsed as a Microsoft serialised Ajax string.

See docs for dateFormat and the 'MS' format.


The number is the timestamp so you could parse it like:

 date = new Date(parseInt(DueDate.substr(6)));

Where DueDate is your "/Date(1304879400000)/" formatted string

0

精彩评论

暂无评论...
验证码 换一张
取 消