Start Time Calculation

Source: Internet
Author: User

One thing I have been pondering over the past few days is how to calculate the total time of my PC from power-on to the present.

Finally, let's look at this function: gettickcount ();

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:

1 # include <stdlib. h> 2 # include <time. h> 3 # include <windows. h> 4 # include <stdio. h> 5 6 typedef struct node 7 {8 int h; 9 int m; 10 int s; 11} * ptime; 12 13 void sleep (long wait ); 14 15 void gettime (); 16 17 int main () 18 {19 ptime times; 20 int flag = 1; 21 char time [1, 128]; 22 do23 {24 _ strtime (time); // gets the current system time (do not include the date) 25 system ("CLS "); // clear screen26 printf ("OS time: % s \ n", time); 27 28 gettime (times); // call gettime () 29 sleep (1000 ); // sleep 1 second30 31 printf ("started Time: % 02d hour % 02d minute % 02d second \ n", times-> H, times-> m, times-> S); 32} while (FLAG); // always cycle33 34 return 0; 35} 36 37 void sleep (long wait) 38 {39 long goal; // define total time40 goal = wait + clock (); 41 while (Goal> clock (); 42} 43 44 ptime gettime (ptime T) 45 {46 int I = gettickcount (); 47 t-> H = (I/1000)/3600; 48 t-> M = (I/1000) /60-T-> H * 60; 49 T-> S = (I/1000)-T-> H * 3600-T-> M * 60; 50 return T; 51}

 

 

 

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.