2010-04-27 10:42:42

Unix Time (Epoch)


C code (copied from wiki  modified in order to convert a known unix epoch time

#include <stdio.h>
#include <time.h>

int main(void)
{
    time_t     now;
    time_t     old;

    struct tm  *ts;
    struct tm  *ots;
    char       buf[80];
    char       buf2[80];
    /* Get the current time */
    now = time(NULL);
    ts  = localtime(&now);

    strftime(buf, sizeof(buf), "%a %Y-%m-%d %H:%M:%S %Z", ts);
    printf("%s\n", buf);

    old = 1257169741;
    ots = localtime(&old);
    strftime(buf2, sizeof(buf2), "%a %Y-%m-%d %H:%M:%S %Z", ots);
    printf("%s\n", buf2);
    return 0;
}

 Tue 2010-04-27 10:27:59 EDT
 Mon 2009-11-02 08:49:01 EST


* $date -d @1257169741
Mon Nov  2 08:49:01 EST 2009

References

Posted by Jeong Han Lee | Permanent link