When I execute the following code:
#include <time.h>
#include <stdio.h>
int main(int argc, char *argv[]) {
time_t rawtime = 0;
time_t secs;
struct tm* timeinfo = gmtime(&rawtime);
printf("rawtime : %s\n", asctime(timeinfo));
secs = mktime(timeinfo);
printf("converted time : %s\n", asctime(gmtime(&secs)));
return 0;
}
The output is :
rawtime : Thu Jan 1 00:00:00 1970
converted time : Wed Dec 31 23:00:00 1969
Why is this one hour difference?
I am running Ubuntu 14.10 64bit btw.
Because mktime converts a local time, not a system time (gmtime), into a timestamp.