The functions gmtime
and localtime
(for UTC and local time respectively) will turn an arbitrary time_t
into a struct tm
with individual fields for year, month and so on.
You can then just use strftime
as you have, or sprintf
to create strings from them, such as with:
char buff[11];
sprintf (buff, "%04d-%02d-%02d",
mytm.tm_year + 1900,
mytm.tm_mon + 1,
mytm.tm_mday);