簡體   English   中英

在C中進行結構tm轉換的時間

[英]Epoch time to struct tm conversion in C

我以秒紀元格式輸入時間。 我需要在幾秒鍾的時間內將struct tm排除在外。

    struct tm epoch_time;
    int seconds = 1441852;
    epoch_time.tm_sec = seconds;

我的目的是讓tm結構在給定的紀元時間(以秒為單位)中填充年,月,日,小時,分鍾和秒的適當值。 在這方面的任何提示都會有所幫助。 謝謝。

struct tm epoch_time;
time_t seconds = 1441852;
memcpy(&epoch_time, localtime(&seconds), sizeof (struct tm));

假設您要本地時間。 如果要使用GMT,請使用gmtime而不是localtime 請注意,這將因錯誤而崩潰。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM