1

How to serialize json object with specific date format ?

json object

{"date": "/Date(-62135596800000)/"}

to string

{"date": "Jan 01,1"}

and i am using extjs as a core library

John Saunders
  • 160,644
  • 26
  • 247
  • 397
neeraj
  • 15
  • 1
  • 5
  • possible duplicate of [How to format a JSON date?](http://stackoverflow.com/questions/206384/how-to-format-a-json-date) – Salman A Nov 14 '12 at 13:46

2 Answers2

0

the following code is not finished, but it should give you what you need to achieve your goal. If not, let me know :)

function rxFn(str,m1) { 
    var d = new Date(parseInt(m1,10));
    return <whatever format you wish based on the date object>
}

function fixDateFormat(jsonObject) {
    for(var i in jsonObject) {
        switch(typeof jsonObject[i]) {
            case 'object':
                fixDateFormat(jsonObject);
                break;
            case 'string':
                jsonObject[i].replace(/Date\(([0-9]+)\)/,rxFn);
        }
    }
}

The basic idea is to loop over the json object recursivly and fix all the date serializations you find.

Martin Jespersen
  • 25,743
  • 8
  • 56
  • 68
0

Thanks Martin for your answer As i am using Extjs library so i have modify the code and work perfectly

neeraj
  • 15
  • 1
  • 5