I'm using stat.st_mtime to get my last modification time of a directory and then store it into a file.txt (stored string is something like that : 1467035651)
Later when I retrieved data from my file.txt, I tried to convert my string from my file.txt to int type since the string contains just seconds but I don't know if it's a good idea to do that.
Is there any way to convert directly to time_t?
According to the reference documentation time_t is just an unspecified numeric format.
Just directly read back the numeric value from the file, there's no need for special conversions:
time_t t;
std::ifstream input("File.txt");
// ...
input >> t;
The function atoll in stdlib.h should work. Example:
time_t t;
char *time_string = //...
t = (time_t) atoll(time_string);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With