VC obtains the system time and program running time

Source: Internet
Author: User

From: http://www.cnblogs.com/yjm0105/archive/2009/07/16/180620.html

1. Use the 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
// ObtainProgramRunning 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 (MS) after the program segment ends)
Str. Format ("Time: % DMS", t2-t1); // The difference between front and back is the running time
Afxmessagebox (STR );
// Obtain 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 );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.