I need to convert st_mtime to string format for passing it to java layer, i try to use this example http://www.cplusplus.com/forum/unices/10342/ but compiler produce errors
invalid conversion from ‘long unsigned int*’ to ‘const time_t* {aka
long int const*}’initializing argument 1 of ‘tm* localtime(const time_t*)’
[-fpermissive]
What i doing wrong, how to get time creation of file using stat function in string presentation.
Help please.
According to the stat(2) man page, the
st_mtimefield is atime_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_tto astruct tmin local time, then, strftime(3) to convert it to achar*string.So you could code something like:
then use
timbufperhaps bystrdup-ing it.NB. I am using
localtime_rbecause it is more thread friendly.