WMIを使用して最後の起動時間を取得するのではなく、とを使用して計算したかったの::GetSystemTime()
です::GetTickCount64
。しかし、ミリ秒に達すると、FILETIMEオブジェクトに戻る方法がわかりません。
私はこれを試しました:
static ULONGLONG FileTimeToMillis(const FILETIME &ft)
{
ULARGE_INTEGER uli;
uli.LowPart = ft.dwLowDateTime; // could use memcpy here!
uli.HighPart = ft.dwHighDateTime;
return uli.QuadPart/10000;
}
static void MillisToSystemTime(ULONGLONG millis, SYSTEMTIME *st)
{
UINT64 t = static_cast<UINT64>(-10000) * static_cast<UINT64>(millis);
FILETIME ft;
ft.dwLowDateTime = static_cast<DWORD(t & 0xFFFFFFFF);
ft.dwHighDateTime = static_cast<DWORD>(t >> 32);
::FileTimeToSystemTime(&ft, st);
}
void main()
{
SYSTEMTIME st, lt, st2, lt2;
::GetSystemTime(&st);
::GetLocalTime(<);
cout << "The system time is: " << st.wHour << ":" << st.wMinute << ":" << st.wSecond << endl;
cout << "The local time is: " << lt.wHour << ":" << lt.wMinute << ":" << lt.wSecond << endl;
FILETIME sft, lft;
::SystemTimeToFileTime(&st, &sft);
::SystemTimeToFileTime(<, &lft);
cout << "The system time in millis is: " << FileTimeToMillis(sft) << endl;
cout << "The local time in millis is: " << FileTimeToMillis(lft) << endl;
MillisToSystemTime(FileTimeToMillis(sft), &st2);
MillisToSystemTime(FileTimeToMillis(sft), <2);
cout << "The system time (post conversion) is: " << st2.wHour << ":" << st2.wMinute << ":" << st2.wSecond << endl;
cout << "The local time (post conversion) is: " << lt2.wHour << ":" << lt2.wMinute << ":" << lt2.wSecond << endl;
}
しかし、私は確かに期待されたものを得ることができません。代わりに、次のようになります。
The system time is: 15:5:2
The local time is: 10:5:2
The system time in millis is: 12984678302935
The local time in millis is: 12984660302935
The system time (post conversion) is: 52428:52428:52428
The local time (post conversion) is: 52428:52428:52428
何か案は?Boostを使用するように、またはBoostを使用できないために、私に言わないでください。