Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

We are adding timezone support to our Ubuntu application.

The time zone info on my machine is in /usr/share/zoneinfo.

  1. Is it always in that directory? If so, where is that specified?
  2. If not, is there system call similar to "gettimeofday(2)" that I can make to find out where it is?

Thanks in advance.

share|improve this question

1 Answer 1

up vote 2 down vote accepted

The search location for the time zones is encoded in the C library (where the various time zone aware functions are found):

$ strings -a /lib/x86_64-linux-gnu/libc.so.6 | grep zoneinfo
/usr/share/zoneinfo

The C library code makes use of this directory as a preprocessor #define, so there is no routine to ask what value it was compiled with.

If you need to parse the the time zone data yourself (as opposed to using the few C library routines available), then hard coding /usr/share/zoneinfo should be fine: if your target platforms follow the Linux File System Hierarchy, you should be safe.

If you are only interested in the local time zone, read /etc/localtime, which will be a copy of the relevant file from /usr/share/zoneinfo.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.