Computer boot time calculation code

Source: Internet
Author: User

Function: GetTickCount returns the number of milliseconds that have elapsed since the operating system was started (elapsed). The returned value is DWORD.

Knowing this, this program is not difficult...

CODE:

Copy codeThe Code is as follows: # include <stdlib. h>
# Include <time. h>
# Include <windows. h>
# Include <stdio. h>

Typedef struct node
{
Int h;
Int m;
Int s;
}
* PTime;

Void sleep (long wait );

Void gettime ();

Int main ()
{
PTime times;
Int flag = 1;
Char time [128];
Do
{
_ Strtime (time); // Gets the current system time (do not include the date)
System ("cls"); // clear screen
Printf ("OS time: % s \ n", time );

Gettime (times); // call gettime ()
Sleep (1000); // sleep 1 second

Printf ("boot time: % 02d hour % 02d minute % 02d second \ n", times-> h, times-> m, times-> s );
} While (flag); // always cycle

Return 0;
}

Void sleep (long wait)
{
Long goal; // define total time
Goal = wait + clock ();
While (goal> clock ());
}

PTime gettime (PTime T)
{
Int I = GetTickCount ();
T-> h = (I/1000)/3600;
T-> m = (I/1000)/60-T-> h * 60;
T-> s = (I/1000)-T-> h * 3600-T-> m * 60;
Return T;
}

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.