4

I see that JSON returned by the API contains dates in the following format:

"creation_date":1364546475
                ^^^^^^^^^^

What's the meaning of it? How can I parse it to get the date in the following format: DDMMYY?

1 Answer 1

3

The date is in "Unix epoch time", as described in the API-docs, Date Formats section.

How you do the conversion depends on what language you are coding in. Here's one way in javascript:

function unixEpochTime_TO_Date_DDMMYY (unixEpochTime, returnUTC) {
    var year, month, day;
    var dateObj = new Date (unixEpochTime * 1000);

    if (returnUTC) {
        year    = dateObj.getUTCFullYear ();
        month   = dateObj.getUTCMonth ();
        day     = dateObj.getUTCDate ();
    }
    else {
        year    = dateObj.getFullYear ();
        month   = dateObj.getMonth ();
        day     = dateObj.getDate ();
    }

    //-- Month starts with 0, not 1.  Compensate.
    month      += 1;

    /*-- Since we want DDMMYY, we need to trim the year and zero-pad
        the day and month.
        Note:  Use YYMMDD, for sorting that makes sense.
    */
    year    = (""  + year) .slice (-2);
    month   = ("0" + month).slice (-2);
    day     = ("0" + day)  .slice (-2);

    return day + month + year;
}

var unixTime    = 1372229551;  //2013-06-26 06:52:31 UTC

console.log (unixEpochTime_TO_Date_DDMMYY (unixTime), " Local");
console.log (unixEpochTime_TO_Date_DDMMYY (unixTime, true), " UTC");


Which outputs:

250613 Local
260613 UTC

On my machine. Your machine may have a different local result.

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.