According to the stat(2) man page, the st_mtime
field is a time_t
(i.e. after reading the time(7) man page, a number of seconds since the unix Epoch).
You need localtime(3) to convert that time_t
to a struct tm
in local time, then, strftime(3) to convert it to a char*
string.
So you could code something like:
time_t t = mystat.st_mtime;
struct tm lt;
localtime_r(&t, <);
char timbuf[80];
strftime(timbuf, sizeof(timbuf), "%c", <);
then use timbuf
perhaps by strdup
-ing it.
NB. I am using localtime_r
because it is more thread friendly.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…