I have a unix time_t , is there any easy way to convert this to a time_t so it:
Something like this:
time_t t = time(NULL);
t -= (t % 86400);
The constant 86400 = 24 * 60 * 60 - a useful number to remember, I think... ;)
Let the computer remember the celestial constants for you:
time_t arg, start_of_hour, start_of_day;
struct tm *temp;
temp = localtime(&arg);
temp->tm_sec = 0;
temp->tm_min = 0;
start_of_hour = mktime(temp);
temp->tm_hour = 0;
start_of_day = mktime(temp);
Or use gmtime
if you prefer.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.