1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| #include <stdio.h>
...
...
LARGE_INTEGER ticksPerSecond;
LARGE_INTEGER tick; // A point in time
LARGE_INTEGER time; // For converting tick into real time
// get the high resolution counter's accuracy
QueryPerformanceFrequency(&ticksPerSecond);
// what time is it?
QueryPerformanceCounter(&tick);
// convert the tick number into the number of seconds
// since the system was started...
time.QuadPart = tick.QuadPart/ticksPerSecond.QuadPart;
//get the number of hours
int hours = time.QuadPart/3600;
//get the number of minutes
time.QuadPart = time.QuadPart - (hours * 3600);
int minutes = time.QuadPart/60;
//get the number of seconds
int seconds = time.QuadPart - (minutes * 60);
AnsiString result = "The system was started ";
result += IntToStr(hours) + " hours ";
result += IntToStr(minutes) + " minutes ";
result += IntToStr(seconds) + " and ";
result += AnsiString(tick.QuadPart % ticksPerSecond.QuadPart);
result += AnsiString("/") + ticksPerSecond.QuadPart;
result += " seconds ago.";
printf("%s", result.c_str()); |
Partager