none
how to control strftime %Z format?

    Question

  • The documentation says that strftime %Z expands to either the time zone abbreviation or full name "depending on registry settings".  But which registry setting, and how do I change it, and what would I change it to?

    My application has limited screen space for a time zone name, so if possible, I'd really like to force the abbreviation when I call strftime, rather than making my program's users fiddle with their registries.  Is there any way (perhaps with a modifier character) to force %Z to always expand to the abbreviation?

    Thursday, July 01, 2010 8:24 PM

Answers

  • summit07 wrote:

    The documentation says that strftime %Z expands to either the time  zone abbreviation or full name "depending on registry
    settings". But which registry setting, and how do I change it, and  what would I change it to?

    My application has limited screen space for a time zone name, so if  possible, I'd really like to force the abbreviation when I
    call strftime, rather than making my program's users fiddle with their  registries. Is there any way (perhaps with a modifier
    character) to force %Z to always expand to the abbreviation? 

    strftime uses  _tzname (as set by _tzset). _tzset reads TZ environment  variable, and if not set, falls back on GetTimeZoneInformation which, in  turn, uses this registry key:

    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time  Zones

    So, if you want a particular abbreviation, just set TZ variable for your  process (see _putenv, SetEnvironmentVariable). I don't believe time zone  abbreviations are stored anywhere in the registry or are available from  any Windows API - you'll have to come up with one on your own. In fact,  I don't think every time zone in use around the world actually has a  standardized three-letter abbreviation associated with it.


    Igor Tandetnik

    • Marked as answer by summit07 Tuesday, July 06, 2010 2:35 PM
    Thursday, July 01, 2010 8:55 PM

All replies

  • summit07 wrote:

    The documentation says that strftime %Z expands to either the time  zone abbreviation or full name "depending on registry
    settings". But which registry setting, and how do I change it, and  what would I change it to?

    My application has limited screen space for a time zone name, so if  possible, I'd really like to force the abbreviation when I
    call strftime, rather than making my program's users fiddle with their  registries. Is there any way (perhaps with a modifier
    character) to force %Z to always expand to the abbreviation? 

    strftime uses  _tzname (as set by _tzset). _tzset reads TZ environment  variable, and if not set, falls back on GetTimeZoneInformation which, in  turn, uses this registry key:

    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time  Zones

    So, if you want a particular abbreviation, just set TZ variable for your  process (see _putenv, SetEnvironmentVariable). I don't believe time zone  abbreviations are stored anywhere in the registry or are available from  any Windows API - you'll have to come up with one on your own. In fact,  I don't think every time zone in use around the world actually has a  standardized three-letter abbreviation associated with it.


    Igor Tandetnik

    • Marked as answer by summit07 Tuesday, July 06, 2010 2:35 PM
    Thursday, July 01, 2010 8:55 PM
  • I don't think every time zone in use around the world actually has a standardized three-letter abbreviation associated with it.

    In fact, there is no such thing as "standardized three-letter abbreviation"
    for time zones.
    What you see in Windows is a MS proprietary convention.

    The only thing close to a standard is the "de facto standard" used in the "Olson database" (http://www.twinsun.com/tz/tz-link.htm)
    It is used by Java, ICU (and Mac OS X), several Linux distros and it is
    the most complete and up-to-date source of time zone info.


    -- Mihai Nita [Microsoft MVP, Visual C++]
    http://www.mihai-nita.net
    ------------------------------------------
    Replace year with _ to get the real email

    Friday, July 02, 2010 6:26 PM
  • Thanks, Igor and Mihai.  I guess I'll have to abbreviate or truncate the strftime-provided long names myself.
    Tuesday, July 06, 2010 12:58 PM