MFC獲取當前時間

2021-09-30 04:07:29 字數 743 閱讀 7617

我們如果使用mfc的話可以用以下**得到

ctime time = ctime::getcurrenttime();///構造ctime物件

int m_nyear = time.getyear();///年

int m_nmonth = time.getmonth();///月

int m_nday = time.getday();///日

int m_nhour = time.gethour();///小時

int m_nminute = time.getminute();///分鐘

int m_nsecond = time.getsecond();///秒

我們還可以用ctime::format函式將ctime物件轉換為字串物件

例如:cstring m_strtime = time.format(/"%y-%m-%d %h:%m:%s/");

執行結果:m_strtime為 2001-8-1 12:11:05

隨便說一下如果我們使用getsystemtime()這個api函式得到系統時間的話,那麼**如下:(整理,www. )

systemtime ti;

getsystemtime(&ti);

我們可以通過讀取systemtime結構體成員直接得到時間

typedef struct _systemtime systemtime, *psystemtime; 

例如:ti.wmilliseconds;可以得到毫秒時間

MFC獲取系統當前時間

1.使用ctime類 cstring str 獲取系統時間 ctime tm tm ctime getcurrenttime str tm.format 現在時間是 y年 m月 d日 x messagebox str,null,mb ok 2 得到系統時間日期 使用getlocaltime syst...

MFC中獲取當前時間

1.使用ctime類 cstring str 獲取系統時間 ctime tm tm ctime getcurrenttime str tm.format 現在時間是 y年 m月 d日 x messagebox str,null,mb ok 2 得到系統時間日期 使用getlocaltime syst...

MFC獲取系統當前時間

mfc獲取系統當前時間 1.使用ctime類 cstring str 獲取系統時間 ctime tm tm ctime getcurrenttime str tm.format 現在時間是 y年 m月 d日 x messagebox str,null,mb ok 2 得到系統時間日期 使用getlo...