locked
how to get the display name of the current timezone RRS feed

  • Question

  • For current timezone,  windows will display a string to indicate which timezone you are in, like the picture below, and I want to the the string.

    Friday, July 6, 2012 3:34 AM

Answers

  • In XP you may try to use GetTimeZoneInformation. The structure TIME_ZONE_INFORMATION sets in member StandardName on my XP system the same value that is used in the registry "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones\<timezonename>"

    for the value <timezonename> but I do not know if it is always be done. It is a try. XP will be very soon outdated and no problem anymore since in is not anymore in active support. :-)


    • Edited by Bordon Friday, July 6, 2012 9:16 AM
    • Proposed as answer by i1friend Wednesday, July 11, 2012 9:15 AM
    • Marked as answer by Elegentin XieModerator Wednesday, July 18, 2012 2:54 AM
    Friday, July 6, 2012 9:16 AM
  • Try this

    TIME_ZONE_INFORMATION Tinfor= {0}; 
    STimeZoneFromRegistry data; 
    DWORD size = sizeof(data); 
    HKEY hkey = NULL; 
    TCHAR zone_key[] = _T("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones\\Central Standard Time"); 
    if ((RegOpenKeyEx(HKEY_LOCAL_MACHINE, zone_key, 0, KEY_QUERY_VALUE, &hkey ) == ERROR_SUCCESS) && 
     (RegQueryValueEx(hkey , "", NULL, NULL, (BYTE *) &data, &size) == ERROR_SUCCESS)) 
    { 
     Tinfor.Bias = binary_data.Bias; 
     Tinfor.DaylightBias = data.DaylightBias; 
     Tinfor.DaylightDate = data.DaylightDate; 
     Tinfor.StandardBias = data.StandardBias; 
     Tinfor.StandardDate = data.StandardDate; 
    } 
    Thanks

    Rupesh Shukla

    Friday, July 6, 2012 5:31 PM

All replies

  • I guess this API descriptions will help. with a combination of API call and registry access you should be able to get the information you want.:

    GetDynamicTimeZoneInformation:

    http://msdn.microsoft.com/en-us/library/windows/desktop/ms724318(v=vs.85).aspx

    DYNAMIC_TIME_ZONE_INFORMATION Structure:

    http://msdn.microsoft.com/en-us/library/windows/desktop/ms724253(v=vs.85).aspx

    GetTimeZoneInformation:

    http://msdn.microsoft.com/en-us/library/windows/desktop/ms724421(v=vs.85).aspx

    TIME_ZONE_INFORMATION Structure:

    http://msdn.microsoft.com/en-us/library/windows/desktop/ms725481(v=vs.85).aspx

    You use the function GetDynamicTimeZoneInformation t oget the "TimeZoneKeyName". Than you are able to access the registy key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones\<timezonename></timezonename>" (please only read access! If you use access all you need an elevated application in vista /7 /8). Than you access the value "Dlt".

    Friday, July 6, 2012 4:50 AM
  • GetDynamicTimeZoneInformation function is supported begin Windows Vista, and my code is demanded to support both xp and win7.

    How can I hit this?

    Thanks Bordon.

    Friday, July 6, 2012 8:43 AM
  • In XP you may try to use GetTimeZoneInformation. The structure TIME_ZONE_INFORMATION sets in member StandardName on my XP system the same value that is used in the registry "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones\<timezonename>"

    for the value <timezonename> but I do not know if it is always be done. It is a try. XP will be very soon outdated and no problem anymore since in is not anymore in active support. :-)


    • Edited by Bordon Friday, July 6, 2012 9:16 AM
    • Proposed as answer by i1friend Wednesday, July 11, 2012 9:15 AM
    • Marked as answer by Elegentin XieModerator Wednesday, July 18, 2012 2:54 AM
    Friday, July 6, 2012 9:16 AM
  • Try this

    TIME_ZONE_INFORMATION Tinfor= {0}; 
    STimeZoneFromRegistry data; 
    DWORD size = sizeof(data); 
    HKEY hkey = NULL; 
    TCHAR zone_key[] = _T("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones\\Central Standard Time"); 
    if ((RegOpenKeyEx(HKEY_LOCAL_MACHINE, zone_key, 0, KEY_QUERY_VALUE, &hkey ) == ERROR_SUCCESS) && 
     (RegQueryValueEx(hkey , "", NULL, NULL, (BYTE *) &data, &size) == ERROR_SUCCESS)) 
    { 
     Tinfor.Bias = binary_data.Bias; 
     Tinfor.DaylightBias = data.DaylightBias; 
     Tinfor.DaylightDate = data.DaylightDate; 
     Tinfor.StandardBias = data.StandardBias; 
     Tinfor.StandardDate = data.StandardDate; 
    } 
    Thanks

    Rupesh Shukla

    Friday, July 6, 2012 5:31 PM
  • STimeZoneFromRegistry can't be recgonized here and I can't get any information about it on msdn libaray, could you tell me where it defined?

    Thanks a lot.

    Saturday, July 7, 2012 4:10 AM
  • I am sorry that is just a structure.

    struct STimeZoneFromRegistry
    {
    long  Bias;
    long  StandardBias;
    long  DaylightBias;
    SYSTEMTIME
    StandardDate;
    SYSTEMTIME
    DaylightDate;
    };

    Same time have a look on this link too .basically a C# example but you will get a basic idea from this.

    http://msdn.microsoft.com/en-us/library/system.timezoneinfo.getsystemtimezones.aspx

    Thanks


    Rupesh Shukla



    Monday, July 9, 2012 11:41 AM
  • In XP you may try to use GetTimeZoneInformation. The structure TIME_ZONE_INFORMATION sets in member StandardName on my XP system the same value that is used in the registry "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones\<timezonename>"

    for the value <timezonename> but I do not know if it is always be done. It is a try. XP will be very soon outdated and no problem anymore since in is not anymore in active support. :-)

    @SaraZC

    Have you tried it in the way I posted here. I tried in on a XP system and for me it works perfect.

    Monday, July 9, 2012 12:52 PM