Alex Rivera | Logout

How do I find the current system timezone?

Asked 2010-06-25T13:58:51.810
28

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?

Edit
Report

1 Answer

0

According to this page, it looks like if you #include <time.h> it will declare the following.

void tzset (void);
extern char *tzname[2];
extern long timezone;
extern int daylight;

Does that give you the information that you need?

answered 2010-06-25T14:13:57.713

Your Answer