Tutorial :Wrong hour in 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  


The time is in UTC according to the docs. Link HERE

For local time you want GetLocalTime()


GetSystemTime() returns the current time in UTC (see the documentation). If you're in EST (which is UTC-4 when DST is in affect), then it would return the current time + 4 hours.


did you check to see if your time you get is in the correct timezone?

Windows has a getlocaltime function as well, that should return the proper time in your timezone.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »