C 系統時間獲取

2021-06-16 13:20:02 字數 759 閱讀 6670

在c++ 中想要獲取當前系統的時候可以使用函式

time_t time (time_t* timer);

使用這個函式如果傳入的 引數不是null 那麼,它就會把當前系統的時間設定到這個指標當中

這個函式返回的 數字是 從 00:00 hours, jan 1, 1970 utc 的 秒

struct tm * localtime (const time_t * timer);
把time_t型別轉換為 本地時間

char* asctime (const struct tm * timeptr);
把本地時間格式化成字串的形式。
示例:
/* localtime example */

#include

/* puts, printf */

#include

/* time_t, struct tm, time, localtime */

int main ()

output:

current local time and date: wed feb 13 17:17:11 2013

當然我們可以對 tm 這個結構體中的資料進行加工處理,獲取我們想要的格式的輸出時間。

c 獲取系統時間

方案 優點 僅使用c標準庫 缺點 只能精確到秒級 include include int main void size t strftime char strdest,size t maxsize,const char format,const struct tm timeptr 根據格式字串生成字...

C 獲取系統時間

include include using namespace std int main 說明 struct tm 在vc 中,我們可以借助ctime時間類,獲取系統當前日期 ctime t ctime getcurrenttime 獲取系統日期 int d t.getday 獲得幾號 int y ...

C 獲取系統時間

time t time time t t 返回從1970.1.1到指定時間 t 的秒數 time t 為64位長整型,即 int64 vc6.0的64位整數分別叫做 int64與unsigned int64,其範圍分別是 2 63,2 63 與 0,2 64 即 922337203685477580...