HOW TO:擷取自啟動後經過的時間
更新:2007 年 11 月
下列程式碼範例會示範如何判斷滴答計數,也就是 Windows 啟動以來經過的毫秒數。這個值儲存在 Environment.TickCount 成員中,因為是 32 位元值,所以大約每 24.9 天會重設為零。
範例
// 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;
}