TimeZone RRS feed

  • Question

  • I use this function to get the TIME_ZONE_INFORMATION for the time specified in lpLocalTime.

    BOOL TzSpecificLocalTimeToSystemTime(
      const TIME_ZONE_INFORMATION *lpTimeZoneInformation,
      const SYSTEMTIME            *lpLocalTime,
      LPSYSTEMTIME                lpUniversalTime

    typedef struct _TIME_ZONE_INFORMATION {
      LONG       Bias;
      WCHAR      StandardName[32];
      SYSTEMTIME StandardDate;
      LONG       StandardBias;
      WCHAR      DaylightName[32];
      SYSTEMTIME DaylightDate;
      LONG       DaylightBias;

    But both StandardName and DaylightName are localized according to the current user default UI language.

    Is there anyway to get the source locale or translator function available to get the StandardName and DaylightName in English instead of default locale.
    When my PC setup in German language, I get the _TIME_ZONE_INFORMATION standard name as
    "ostliche Standarzeit" which is in german language. I want to get it as 'Eastern Standard Time'. Can anyone help me?

    • Edited by Neptune123 Thursday, December 5, 2019 3:51 AM
    Thursday, December 5, 2019 3:49 AM

All replies

  • Hello,

    the StandardName and DaylightName are always localized. This cannot be turned off with MS APIs.

    You could use the library ICU instead:

    Regards, Guido

    Thursday, December 5, 2019 7:39 AM
  • I installed the German Language Pack on my system.  The system's main language is US English.

    Then I wrote a small console application that uses SetThreadPreferredUILanguages function

     to change a thread's preferred language to German.  The application called GetTimeZoneInformation from the main thread (language preferences unchanged) and from a worker thread (use German) and displayed the results with MessageBoxW.

    This is the sample code  -

    #include <Windows.h>
    #include <strsafe.h>
    #include <process.h>
    UINT __stdcall GetGermanTZI(LPVOID pv)
    	ULONG uLangs = 0;
    	if (SetThreadPreferredUILanguages(MUI_LANGUAGE_NAME, L"de-DE\0en-US\0", &uLangs))
    		if (GetTimeZoneInformation(&tzi_de) != TIME_ZONE_ID_INVALID)
    			WCHAR szMsg[256];
    			StringCchPrintfW(szMsg, ARRAYSIZE(szMsg), L"Standard: %s\nDaylight: %s", tzi_de.StandardName, tzi_de.DaylightName);
    			MessageBoxW(NULL, szMsg, L"German Names", MB_OK);
    		MessageBoxW(NULL, L"SetThreadPreferredUILanguages failed", L"Error", MB_OK);
    	return 0;
    int main()
    	HANDLE hThread = reinterpret_cast<HANDLE>(_beginthreadex(nullptr, 0, GetGermanTZI, nullptr, 0, nullptr));
    	if (GetTimeZoneInformation(&tzi_en) != TIME_ZONE_ID_INVALID)
    		WCHAR szMsg[256];
    		StringCchPrintfW(szMsg, ARRAYSIZE(szMsg), L"Standard: %s\nDaylight: %s", tzi_en.StandardName, tzi_en.DaylightName);
    		MessageBoxW(NULL, szMsg, L"English Names", MB_OK);
    	if (hThread)
    		WaitForSingleObject(hThread, INFINITE);
    	return 0;

    Thursday, December 5, 2019 7:26 PM