2009-05-04 2 views
4
// 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 

답변

1

시간이 올바른 시간대인지 확인 했습니까?

Windows에는 getlocaltime 기능이있어 시간대에 적절한 시간을 반환해야합니다.

16

시간은 문서에 따라 UTC로 표시됩니다. 현지 시간에 대한 링크 HERE

당신은 GetLocalTime()

3

GetSystemTime()은 UTC의 현재 시간을합니다 (documentation 참조)를 반환합니다. EST (DST가 영향을받을 때 UTC-4) 인 경우 현재 시간 + 4 시간을 반환합니다.

관련 문제