The current system time is displayed in the MFC dialog box.

Source: Internet
Author: User

In the dialog box, the edit box ID is idc_time and the associated variable is m_time of cstring.

Add code in oninitdialog:
Cstring strtime;
Ctime TM;
TM = ctime: getcurrenttime (); // get the current system time
Strtime = TM. Format ("% Y % m % d % x"); // format the system time. Even if the system time is displayed in the format set in the format
Setdlgitemtext (idc_time, strtime); // The initialization edit box is displayed.
Settimer (, null); // start the timer

Add the wm_timer message processing function to the dialog box and add the following code:
Cstring strtime;
Ctime TM;
TM = ctime: getcurrenttime ();
Strtime = TM. Format ("% Y-% m-% d % H: % m: % s ");
Setdlgitemtext (idc_time, strtime); // display the system time

The running result of the above program section is: June 25 10:10:10

Other time styles: (content between "" in the format brackets)
1. "% Y % m % d % x" Y: 2009 Y: 09 m: 06 D: 05
2. "% C": 06/25/09 10:10:10

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.