Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6884863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:33:46+00:00 2026-05-27T05:33:46+00:00

How do I get the Olson timezone name (such as Australia/Sydney ) corresponding to

  • 0

How do I get the Olson timezone name (such as Australia/Sydney) corresponding to the value given by C’s localtime call?

This is the value overridden via TZ, by symlinking /etc/localtime, or setting a TIMEZONE variable in time-related system configuration files.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T05:33:46+00:00Added an answer on May 27, 2026 at 5:33 am

    I think best bet is to go thru all pytz timezones and check which one matches local timezone, each pytz timezone object contains info about utcoffset and tzname like CDT, EST, same info about local time can be obtained from time.timezone/altzone and time.tzname, and I think that is enough to correctly match local timezone in pytz database e.g.

    import time
    import pytz
    import datetime
    
    local_names = []
    if time.daylight:
        local_offset = time.altzone
        localtz = time.tzname[1]
    else:
        local_offset = time.timezone
        localtz = time.tzname[0]
    
    local_offset = datetime.timedelta(seconds=-local_offset)
    
    for name in pytz.all_timezones:
        timezone = pytz.timezone(name)
        if not hasattr(timezone, '_tzinfos'):
            continue#skip, if some timezone doesn't have info
        # go thru tzinfo and see if short name like EDT and offset matches
        for (utcoffset, daylight, tzname), _ in timezone._tzinfos.iteritems():
            if utcoffset == local_offset and tzname == localtz:
                local_names.append(name)
    
    print local_names
    

    output:

    [‘America/Atikokan’, ‘America/Bahia_Banderas’,
    ‘America/Bahia_Banderas’, ‘America/Belize’, ‘America/Cambridge_Bay’,
    ‘America/Cancun’, ‘America/Chicago’, ‘America/Chihuahua’,
    ‘America/Coral_Harbour’, ‘America/Costa_Rica’, ‘America/El_Salvador’,
    ‘America/Fort_Wayne’, ‘America/Guatemala’,
    ‘America/Indiana/Indianapolis’, ‘America/Indiana/Knox’,
    ‘America/Indiana/Marengo’, ‘America/Indiana/Marengo’,
    ‘America/Indiana/Petersburg’, ‘America/Indiana/Tell_City’,
    ‘America/Indiana/Vevay’, ‘America/Indiana/Vincennes’,
    ‘America/Indiana/Winamac’, ‘America/Indianapolis’, ‘America/Iqaluit’,
    ‘America/Kentucky/Louisville’, ‘America/Kentucky/Louisville’,
    ‘America/Kentucky/Monticello’, ‘America/Knox_IN’,
    ‘America/Louisville’, ‘America/Louisville’, ‘America/Managua’,
    ‘America/Matamoros’, ‘America/Menominee’, ‘America/Merida’,
    ‘America/Mexico_City’, ‘America/Monterrey’,
    ‘America/North_Dakota/Beulah’, ‘America/North_Dakota/Center’,
    ‘America/North_Dakota/New_Salem’, ‘America/Ojinaga’,
    ‘America/Pangnirtung’, ‘America/Rainy_River’, ‘America/Rankin_Inlet’,
    ‘America/Resolute’, ‘America/Resolute’, ‘America/Tegucigalpa’,
    ‘America/Winnipeg’, ‘CST6CDT’, ‘Canada/Central’, ‘Mexico/General’,
    ‘US/Central’, ‘US/East-Indiana’, ‘US/Indiana-Starke’]

    In production you can create such a mapping beforehand and save it instead of iterating always.

    Testing script after changing timezone:

    $ export TZ=’Australia/Sydney’
    $ python get_tz_names.py
    [‘Antarctica/Macquarie’, ‘Australia/ACT’, ‘Australia/Brisbane’,
    ‘Australia/Canberra’, ‘Australia/Currie’, ‘Australia/Hobart’,
    ‘Australia/Lindeman’, ‘Australia/Melbourne’, ‘Australia/NSW’,
    ‘Australia/Queensland’, ‘Australia/Sydney’, ‘Australia/Tasmania’,
    ‘Australia/Victoria’]

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I get this error when I try to call $func('something') : if(($object instanceof MyObject)
I get an Access is Denied error message when I use the strong name
I get this error: Can't locate Foo.pm in @INC Is there an easier way
On Linux, I need to find the currently configured timezone as an Olson location.
get current array position pointer while doing foreach $object->result_array() Hi, consider this, a case.
Get month of a given date which is stored in a PHP time variable
I get this exception: Exception in thread main java.lang.ArrayIndexOutOfBoundsException: 100 at Vindu.<init>(setevelger.java:64) at setevelger.main(setevelger.java:22)
I get this error while installing cmake on my machine. Error: Target org.macports.configure returned:
I get FIX message string (ASCII) as ByteBuffer. I parse tag value pairs and
i get date from xml in this format: 7/16/2010 (mm/dd/yyyy) i have in my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.