Skip to content
Advertisement

How do you get info for an arbitrary time zone in Linux / POSIX?

Ideally, what I’d like to be able to do is take the name of a time zone and call a function to ask for its corresponding time zone info (offset from UTC, DST offset, dates for DST switch, etc.) in Linux. However, I can’t find any way to do this. The information exists in /usr/share/zoneinfo/ in the various binary files there, but I don’t know how to read them or if there is a way to get the OS to give you the information in them rather than having to read them in yourself. So, I’m looking for a way to get this information. Ideally, there would be a posix function which would do it for you so that it would work on POSIX systems other than Linux, but if there isn’t, I’d at least like to know the proper way (or at least the best way) to get the time zone info for an arbitrary time zone in Linux.

Advertisement

Answer

The tzcode package (found along with the data at ftp://ftp.iana.org/tz/releases) contains a description of the tzfile format along with a header file tzfile.h for working directly with that data.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement