簡體   English   中英

如何在C中從struct tm轉換為long int?

[英]how to convert from struct tm to long int in C?

這是一個簡單的問題......有沒有辦法轉換struct tm ct; 到一個長整數? 這是我的代碼的樣子:

struct tm ct;
    scanf("%d", &ct.tm_sec);
    scanf("%d", &ct.tm_min);    
    scanf("%d", &ct.tm_hour);
    scanf("%d", &ct.tm_mday);
    scanf("%d", &ct.tm_mon);
    scanf("%d", &ct.tm_year);

您可以使用mktime()函數將struct tm轉換為time_t ,這是一個整數值。

你想得到一個time_t,它代表自1970年1月1日00:00:00以來的秒數

使用mktime():

time_t mktime(struct tm * timeptr);

http://www.cplusplus.com/reference/clibrary/ctime/mktime/

暫無
暫無

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

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