获取系统正常运行时间 [英] Getting System Up-time
问题描述
我无法确定系统正在运行多长时间。我现在太累了,但没有什么可做。我使用GetTickCount()获得毫秒,但我必须转换他们人类可读的格式。我尝试这样的,但我得到奇怪的结果。
I'm having trouble to determine how long system is running. I'm just too tired for now, but have nothing to do. I used GetTickCount() to get Milliseconds, but I have to convert them human readable format. I tried something like this but I get strange results.
void GetUpTime(DWORD Tick) //GetTickCount() argument.
{
wchar_t temp[256] = {0};
ZeroMemory(tmpBuff, sizeof(tmpBuff));
wsprintfW(temp, L"%uh %um %us", Tick/60, Tick/60*60, Tick/60*60*60);
lstrcpyW(Time, tmpBuff);
}
我想这里,Tick / 60 =秒,Tick / 60 * 60 =分钟,Tick / 60 * 60 * 60 =小时。但我需要像:1h 5m 36s不是整个对话。
谨慎。
as I guess here, Tick/60 = seconds, Tick/60*60 = minutes and Tick/60*60*60 = hours. but I need something like: 1h 5m 36s not the whole conversation. Regards.
推荐答案
Tick / 60 * 60
与(Tick / 60)* 60
相同的东西,这显然不是你想要的。您可能表示 Tick /(60 * 60)
。
Tick/60*60
means the same thing as (Tick/60)*60
, which is clearly not what you want. You likely meant Tick/(60*60)
instead.
DWORD seconds = Tick / 1000; /* Milliseconds -> seconds */
DWORD minutes = seconds / 60; /* Seconds -> minutes */
DWORD hours = minutes / 60; /* Minutes -> hours */
/* Adjust seconds and minutes to leave only the remainder. */
seconds %= 60;
minutes %= 60;
wsprintfW(temp, L"%uh %um %us", hours, minutes, seconds);
这篇关于获取系统正常运行时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!