mehul9595
mehul9595

Reputation: 1955

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

I am building an App using Sencha touch api. I have a 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

Upvotes: 2

Views: 2248

Answers (2)

Joel Malone
Joel Malone

Reputation: 1324

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.

Upvotes: 3

Chris Farmiloe
Chris Farmiloe

Reputation: 14185

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

Upvotes: 0

Related Questions