[英]Why is there a one hour difference between two time_t values when converting to tm struct and back?
[英]“round” time_t to day/hour?
我有一个unix time_t,有没有简单的方法将它转换为time_t所以它:
像这样的东西:
time_t t = time(NULL);
t -= (t % 86400);
常数86400 = 24 * 60 * 60 - 一个有用的数字要记住,我想......;)
让计算机为你记住天体常数:
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);
或者如果您愿意,可以使用gmtime
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.