I have seconds (say x, x is long long data type) after epoch. I wish to convert it into unix time using <ctime> library. The issue is, I want a time_t variable for gmtime() to work, I am unable to make my x (long long) converted to time_t.
This is what am doing:
//x is number of seconds after epoch, I want that in unix time
time_t t=x;
printf("%s\n",asctime(gmtime(&t)));
Can I somehow typecast x into time_t?
Just cast it?
It will cut of the top 32 bits but you still have over 25 years until you really need 64-bit timestamps. 🙂
Of course, there might be trouble if your epoch is not the same as the POSIX epoch (1970-01-01 00:00:00).