How to: Retrieve Time Elapsed Since Startup (C++/CLI)

The following code example demonstrates how to determine the tick count, or number of milliseconds that have elapsed since Windows was started. This value is stored in the Environment.TickCount member and, because it is a 32-bit value, resets to zero approximately every 24.9 days.

Example

// startup_time.cpp
// compile with: /clr
using namespace System;

int main( ) 
{
   Int32 tc = Environment::TickCount;
   Int32 seconds = tc / 1000;
   Int32 minutes = seconds / 60;
   float hours = static_cast<float>(minutes) / 60;
   float days = hours / 24;

   Console::WriteLine("Milliseconds since startup: {0}", tc);
   Console::WriteLine("Seconds since startup: {0}", seconds);
   Console::WriteLine("Minutes since startup: {0}", minutes);
   Console::WriteLine("Hours since startup: {0}", hours);
   Console::WriteLine("Days since startup: {0}", days);

   return 0;
}

See Also

Other Resources

Windows Operations (C++/CLI)

.NET Programming Guide