[英]“round” time_t to day/hour?
I have a unix time_t , is there any easy way to convert this to a time_t so it: 我有一个unix time_t,有没有简单的方法将它转换为time_t所以它:
Something like this: 像这样的东西:
time_t t = time(NULL);
t -= (t % 86400);
The constant 86400 = 24 * 60 * 60 - a useful number to remember, I think... ;) 常数86400 = 24 * 60 * 60 - 一个有用的数字要记住,我想......;)
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. 或者如果您愿意,可以使用
gmtime
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.