How to obtain system time in MFC
Default category: read 7 Comments 0 font size: large medium small 1. Use ctime class
Cstring STR; // obtain the system time
Ctime TM; TM = ctime: getcurrenttime ();
STR = TM. Format ("the current time is % Y % m month % d % x"); MessageBox (STR, null, mb_ OK );
2: Get the system time and date (using getlocaltime)
Systemtime st;
Cstring strdate, strtime;
Getlocaltime (& St );
Strdate. Format ("% 4D-% 2D-% 2D", st. wyear, st. wmonth, st. wday );
Strtime. Format ("% 2D: % 2D: % 2D", st. whour, st. wminute, st. wsecond );
3. Use gettickcount // to obtain
Program Running time
Long T1 = gettickcount (); // gets the system Runtime (MS) before the start of the program segment)
Sleep (500); long T2 = gettickcount (); // gets the system runtime after the program segment ends (MS)
Str. Format ("Time: % DMS", t2-t1); // The difference between front and back is the running time
Afxmessagebox (STR); // gets the system running time
Long T = gettickcount ();
Cstring STR, str1;
Str1.format ("when the system is running % d", T/3600000 );
STR = str1; T % = 3600000;
Str1.format ("% d points", T/60000 );
STR + = str1; T % = 60000;
Str1.format ("% d seconds", T/1000 );
STR + = str1; afxmessagebox (STR); http://blog.163.com/zhang672404141@126/blog/static/69227982200951234156411/