C C 獲取系統時間

2022-05-23 01:18:13 字數 471 閱讀 3127

c/c++獲取系統時間需要使用windows api,包含標頭檔案"windows.h"。

系統時間的資料型別為systemtime,可以在winbase.h中查詢到如下定義:

typedef struct_systemtime  systemtime, *psystemtime, *lpsystemtime;

其中包含了年、月、日、時、分、秒、毫秒、一周中的第幾天(從周一開始計算)等8條資訊,均為word型別。

在vc++6.0中word為無符號短整型,定義如下:

typedef unsigned short      word;

獲取時間的函式有兩個:getlocaltime()獲取本地時間;getsystemtime()獲取格林尼治標準時間。

#include #include "windows.h"

intmain()

c c 獲取系統時間

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

C C 獲取系統時間

在程式設計過程中,經常需要獲取系統時間,例如記錄日誌或資料的時候,需要把時間也記錄下來,現在介紹c c 獲取系統時間的幾種方法吧。1 mfc方法,只適合windows mfc atl程式設計 ctime time ctime getcurrenttime cstring str time.forma...

C C 獲取當前系統時間

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