// Simple program to get the date and time on Windows
// It compiles and works fine but displays the wrong hour!
// Using Visual C++ 2008 Express on XP SP2
#include <Windows.h>
#include <iostream>
using namespace std;
void main()
{
SYSTEMTIME st;
GetSystemTime(&st);
cout << "Year : " << st.wYear << "\n";
cout << "Month : " << st.wMonth << "\n";
cout << "Day : " << st.wDay << "\n";
// The following line displays the wrong hour, off by 4 hours.
// What gives?
cout << "Hour : " << st.wHour << "\n";
cout << "Minute : " << st.wMinute << "\n";
cout << "Second : " << st.wSecond << "\n";
}
// TIA guys!
// -- Bert
最佳答案
根据文档,时间以UTC为单位。链接 HERE
对于本地时间,您需要 GetLocalTime()
关于c++ - C++中的错误时间,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/821490/