Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8606369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:04:41+00:00 2026-06-12T03:04:41+00:00

I want to convert the timestamp to customized date format right after the server

  • 0

I want to convert the timestamp to customized date format right after the server returns the data.
I tried to use the “convert” in Ext.data.field : http://docs.sencha.com/ext-js/4-1/#!/api/Ext.data.Field-cfg-convert

But I cannot make it right. This is my model.

Ext.define('AM.model.Comment',{
    extend: 'Ext.data.Model',
    fields: [
        { name: 'createdTime', type: 'date', convert:function(v,record){record.parseDate(v,record);}}, // datetime
    ],

    proxy: {
        type: 'rest',
        url:'../comments',
        writer:{
            type:'json'
        },
        reader: {
            type: 'json'
        }
    },
    parseDate:function(v,record){
        console.log(v); //show 1347465600000 
        console.log(Ext.Date.format(new Date(v), 'Y-m-d')); //show 2012-09-13
        return Ext.Date.format(new Date(v), 'Y-m-d');
    }
});

After loading, I checked firebug and found the field “createdTime” is “undefined”.
Can someone point out my mistake? Thanks!

I can achieve that without using “convert”, just use Ext.Date.format(new Date(v), 'Y-m-d') in other component. But I think it will be better to do that in model. Then every component can always read the right date format as querying it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T03:04:42+00:00Added an answer on June 12, 2026 at 3:04 am

    I found a solution. Instead of using “convert”, I override the getData() method of reader.

    Ext.define('AM.model.Comment',{
        extend: 'Ext.data.Model',
        fields: [
            { name: 'createdTime', type: 'datetime'},
        ],
    
        proxy: {
            type: 'rest',
            url:'../comments',
            writer:{
                type:'json'
            },
            reader: {
                type: 'json',
                getData:function(data){
                    for(i = 0; i < data.length; i++){
                        data[i].createdTime = Ext.Date.format(new Date(data[i].createdTime), "Y-m-d");
                    }
                    return data;
                }
            }
        }
    });
    

    If anyone has better solution, please tell me. And I still wonder why “convert” didn’t work.If anyone know the reason, please tell me, too. Thanks!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a timestamp I want to convert to a date. I tried this
Facebook returns 'created_time' in this format: 2012-07-23T08:52:04+0000 I want to convert this timestamp to
I have a UTC timestamp. I want to convert it into YYYY/MM/DD format in
I want to convert string Date into Timestamp in java. The following coding i
I've tried to convert a UNIX Timestamp to todays date time. Like I have
I want to convert a data string into a timestamp (which would include the
Possible Duplicate: How to convert date to timestamp in PHP? I want to transfer
I want convert GMT time to EST time and get a timestamp. I tried
I need to convert or format my timestamp to date in the report I
I want to convert a timestamp in MySQL to a date. I would like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.