在C ++中错误的时间

// 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。 链接这里

当地时间你想GetLocalTime()

GetSystemTime()返回UTC中的当前时间(请参阅文档 )。 如果您在EST(当DST正在影响UTC-4时),那么它将返回当前时间+4小时。

你是否检查你的时间是否在正确的时区?

Windows也有一个getlocaltime函数,它应该在你的时区返回适当的时间。