![](/img/trans.png)
[英]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.