Reputation: 161
I'm trying to get the last access time of a file in epoch format in C but I can't figure out an easy way to do so. I know you can get the last access/last modified time of a file with stat()
and then using st_atime
but that returns the time back in a nice human readable format. Is there any way to return the time back in epoch format?
Upvotes: 0
Views: 1084
Reputation: 753625
That's puzzling; the value returned by stat()
in st_atime
is a time in seconds since The Epoch (1970-01-01 00:00:00 +00:00). It is not neatly formatted; you have to dissect it, probably with localtime()
or gmtime()
or one of the re-entrant variants of those functions, and then format it with one of the other time formatting functions (ctime()
, asctime()
or, better, strftime()
).
Upvotes: 2