1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include <err.h> #include <time.h> #include <stdio.h> #include "misc.h" char * date(int timestamp) { char *buf; time_t *t; if(!(buf = malloc(20))) err(1, "malloc"); t = localtime(×tamp); strftime(buf, 20, "%Y-%m-%d %H:%M", t); return buf; }