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

  • Home
  • SEARCH
  • 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 879913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T12:00:45+00:00 2026-05-15T12:00:45+00:00

On Linux, I need to find the currently configured timezone as an Olson location.

  • 0

On Linux, I need to find the currently configured timezone as an Olson location. I want my (C or C++) code to be portable to as many Linux systems as possible.

For example. I live in London, so my current Olson location is “Europe/London”. I’m not interested in timezone IDs like “BST”, “EST” or whatever.

Debian and Ubuntu have a file /etc/timezone that contains this information, but I don’t think I can rely on that file always being there, can I? Gnome has a function oobs_time_config_get_timezone() which also returns the right string, but I want my code to work on systems without Gnome.

So, what’s the best general way to get the currently configured timezone as an Olson location, on Linux?

  • 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-15T12:00:46+00:00Added an answer on May 15, 2026 at 12:00 pm

    It’s hard to get a reliable answer. Relying on things like /etc/timezone may be the best bet.

    (The variable tzname and the tm_zone member of struct tm, as suggested in other answers, typically contains an abbreviation such as GMT/BST etc, rather than the Olson time string as requested in the question).

    • On Debian-based systems (including Ubuntu), /etc/timezone is a file containing the right answer.
    • On some Redhat-based systems (including at least some versions of CentOS, RHEL, Fedora), you can get the required information using readlink() on /etc/localtime, which is a symlink to (for example) /usr/share/zoneinfo/Europe/London.
    • OpenBSD seems to use the same scheme as RedHat.

    However, there are some issues with the above approaches. The /usr/share/zoneinfo directory also contains files such as GMT and GB, so it’s possible the user may configure the symlink to point there.

    Also there’s nothing to stop the user copying the right timezone file there instead of creating a symlink.

    One possibility to get round this (which seems to work on Debian, RedHat and OpenBSD) is to compare the contents of the /etc/localtime file to the files under /usr/share/zoneinfo, and see which ones match:

    eta:~% md5sum /etc/localtime
    410c65079e6d14f4eedf50c19bd073f8  /etc/localtime
    eta:~% find /usr/share/zoneinfo -type f | xargs md5sum | grep 410c65079e6d14f4eedf50c19bd073f8
    410c65079e6d14f4eedf50c19bd073f8  /usr/share/zoneinfo/Europe/London
    410c65079e6d14f4eedf50c19bd073f8  /usr/share/zoneinfo/Europe/Belfast
    410c65079e6d14f4eedf50c19bd073f8  /usr/share/zoneinfo/Europe/Guernsey
    410c65079e6d14f4eedf50c19bd073f8  /usr/share/zoneinfo/Europe/Jersey
    410c65079e6d14f4eedf50c19bd073f8  /usr/share/zoneinfo/Europe/Isle_of_Man
    ...
    ...
    

    Of course the disadvantage is that this will tell you all timezones that are identical to the current one. (That means identical in the full sense – not just “currently at the same time”, but also “always change their clocks on the same day as far as the system knows”.)

    Your best bet may be to combine the above methods: use /etc/timezone if it exists; otherwise try parsing /etc/localtime as a symlink; if that fails, search for matching timezone definition files; if that fails – give up and go home 😉

    (And I have no idea whether any of the above applies on AIX…)

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

Sidebar

Related Questions

I need to find the PID of the current running process on a Linux
I would need to find a way in Bash (Linux shell in general) to
I am writing a system monitor for Linux and want to include some watchdog
I need to find a right way to prevent two running instances of my
We have a quite large (280 binaries) software project under Linux and currently it
I am writing code for a real-time program running in an embedded Linux system.
I need a terminal to a Linux vm inside my osx installation. Its a
/*kprobe_example.c*/ #define FUNCNAME alloc_file /* Find something better. printk() isnt recommended */ #include <linux/kernel.h>
Searched all over, but haven't been able to find a solution. I need to
I'm currently getting a 500 error (apparently) on a url of mine, even though

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.