system boot time is the value returned by GetTickCount(). If you want to know the actual date/time, call time() function in time.h, then localtime() to get struct tm pointer. From that subtract the number of seconds returned by GetTickCount(), pass that result to mktime() (from time.h) which will do all the math needed to normalize the date/time in struct tm. Volla -- you have the actual date/time the system was booted.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
#include <iostream>
#include <iomanip>
#include <ctime>
#include <windows.h>
using namespace std;
int main()
{
DWORD ticks = GetTickCount() / 1000;
cout << ticks << "\n";
time_t now = time(0);
struct tm* tm = localtime(&now);
tm->tm_sec -= ticks;
now = mktime(tm);
cout << setw(2) << setfill('0') << tm->tm_mon << ":" << setw(2) << setfill('0') <<
tm->tm_mday << ":" << setw(4) <<tm->tm_year + 1900 << " ";
cout << setw(2) << setfill('0') << tm->tm_hour << "/" <<
setw(2) << setfill('0') << tm->tm_min << "/" << setw(2) << setfill('0') << tm->tm_sec << "\n";
}
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
Wow, a 4 year bump, and the answer is still the same?
Did the bumper bother to read anything, or just attach the same question based on the result of a feeble search?
Salem
Posting Sage
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953