Stack Apps is a question and answer site for apps, scripts, and development with the Stack Exchange API. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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


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

share|improve this question
up vote 3 down vote accepted

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.

share|improve this answer
Yes, thank you! – Ionică Bizău Jun 30 '13 at 10:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .