I want to get the unix timestamp of the beginning of the current (or any given) hour in c / C ++.
I have it:
time_t get_current_hour () {
time_t beginning_of_hour;
struct tm * ptm;
time (& beginning_of_hour);
ptm = gmtime (& beginning_of_hour);
ptm-> tm_min = 0;
ptm-> tm_sec = 0;
ptm-> tm_zone = (char *) "GMT";
beginning_of_hour = mktime (ptm);
return beginning_of_hour;
}
Which works, but with a heavy load, many of the results are not the beginning of the current hour, but the actual time.
Is there a better way to solve the problem? Why does the function return the current time?
Kindly inform Akos
source share