I have the following function to get the seconds since epoch for midnight of the present day.
long int midnight_time()
{
time_t t;
struct tm *local;
t = time(NULL);
struct tm timeinfo;
local = localtime(&t);
timeinfo.tm_year = local->tm_year;
timeinfo.tm_mon = local->tm_mon;
timeinfo.tm_mday = local->tm_mday;
timeinfo.tm_hour = 0;
timeinfo.tm_min=0;
timeinfo.tm_sec=0;
long int midnight_epoch = mktime(&timeinfo);
return midnight_epoch;
}
When I called this function twice in code right after each other, e.g.
cout<<midnight_time()<<endl;
cout<<midnight_time()<<endl;
I consistently get radically different results, for example: 1367816400 1367812800
This is a difference of nearly 4000 seconds. I would expect the numbers to be the same. Can anybody see what I am doing wrong?