tzset(3)
๐ tzset(3) โ okay bestie, let's talk TIME ZONES ๐
No cap, this is the page for tzset, tzname, timezone, and daylight โ the whole little squad that initializes your time conversion info. It lives in the Library Functions Manual, and girlypop, it is exactly as chaotic as time zones themselves. โจ
๐ธ LIBRARY ๐ธ
Standard C library (libc, -lc) ๐ซถ
โจ SYNOPSIS โจ
#include <time.h>
void tzset(void);
extern char *tzname[2];
extern long timezone;
extern int daylight;
๐ Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
tzset():
_POSIX_C_SOURCE
tzname:
_POSIX_C_SOURCE
timezone, daylight:
_XOPEN_SOURCE
|| /* glibc >= 2.19: */ _DEFAULT_SOURCE
|| /* glibc <= 2.19: */ _SVID_SOURCE
Like, do NOT forget the macros or the compiler will simply not let you have your little functions. ๐
๐ฆ DESCRIPTION ๐ฆ
Okay so the way that tzset() works is: it initializes the tzname variable from the TZ environment variable. And here's the cute part โ you don't even have to call it, because the other time conversion functions that depend on the timezone call it for you automatically. Not me being needy at all, it's just handled. ๐
In a System-V-like environment it will also set these variables:
timezoneโ seconds West of UTC (yes, West, we'll get to that)daylightโ set to0if this timezone has no daylight saving time rules, or nonzero if there is a time, past, present, or future when daylight saving time applies
Heads up bestie:tzset()initializes those three variables to unspecified values if the timezone is a geographical timezone like"America/New_York"(more on that below). So don't go trusting them, okay? ๐ฉ
๐ง Where does the timezone even come from
If the TZ variable is not in the environment, the system timezone is used. And how does the system get its timezone? By copying, or linking, a file in the tzfile(5) format to /etc/localtime. A whole database of these files may live in the system timezone directory (peep the FILES section further down ๐).
If TZ does appear in the environment, but its value is empty, or its value can't be interpreted using any of the formats down below, then Coordinated Universal Time (UTC) is used. Simple as that.
๐ The two formats (this is the main character section)
A nonempty value of TZ can be one of two formats โ and either one can be preceded by a colon, which is just ignored. Rude, but fine. ๐
Format 1: the inline string ๐
The first format is a string of characters that directly represent the timezone to be used:
std offset[dst[offset][,start[/time],end[/time]]]
There are no spaces in the specification. Groundbreaking. Here's the breakdown:
- The
stdstring specifies an abbreviation for the timezone and must be three or more alphabetic characters. When you enclose it between the less-than (<) and greater-than (>) signs, the character set is expanded to include the plus (+) sign, the minus (-) sign, and digits. - The
offsetstring immediately followsstdand specifies the time value to be added to the local time to get Coordinated Universal Time (UTC). The offset is positive if the local timezone is west of the Prime Meridian and negative if it is east. (Yes, it's backwards from what your brain wants. It's giving "we did this on purpose." ๐ญ) - The hour must be between
0and24, and the minutes and seconds00and59:
[+|-]hh[:mm[:ss]]
- The
dststring andoffsetspecify the name and offset for the corresponding daylight saving timezone. If the offset is omitted, it defaults to one hour ahead of standard time.
The start field says when daylight saving time goes into effect, and the end field says when the change is made back to standard time. These fields may have the following formats:
Jnโ This specifies the Julian day with n between1and365. Leap days are not counted. In this format, February 29 can't be represented; February 28 is day59, and March 1 is always day60. ๐nโ This specifies the zero-based Julian day with n between0and365. February 29 is counted in leap years. Slay, inclusivity.Mm.w.dโ This specifies day d (0 <= d <= 6) of week w (1 <= w <= 5) of month m (1 <= m <= 12). Week 1 is the first week in which day d occurs and week 5 is the last week in which day d occurs. Day0is a Sunday.
The time fields specify when, in the local time currently in effect, the change to the other time occurs. They use the same format as offset, except that the hour can be in the range [-167, 167] to represent times before and after the named day. If omitted, the default is 02:00:00. ๐
Here's an example for New Zealand, where the standard time (NZST) is 12 hours ahead of UTC, and daylight saving time (NZDT), 13 hours ahead of UTC, runs from September's last Sunday, at the default time 02:00:00, to April's first Sunday at 03:00:00:
TZ="NZST-12:00:00NZDT-13:00:00,M9.5.0,M4.1.0/3"
Ate. โจ
Format 2: the geographical format ๐บ๏ธ
The second โ or "geographical" โ format specifies that the timezone information should be read from a file:
filespec
The filespec specifies a tzfile(5)-format file to read the timezone information from. If filespec does not begin with a /, the file specification is relative to the system timezone directory.
If the specified file cannot be read or interpreted, Coordinated Universal Time (UTC) is used โ however, applications should not depend on random filespec values standing for UTC, as TZ formats may be extended in the future. So no relying on the fallback, bestie, that's undefined-behavior-adjacent energy. ๐ซ
Here's an example, once more for New Zealand:
TZ="Pacific/Auckland"
๐ ENVIRONMENT ๐
TZโ If this variable is set, its value takes precedence over the system configured timezone.TZDIRโ If this variable is set, its value takes precedence over the system configured timezone database directory path.
๐ FILES ๐
/etc/localtimeโ The system timezone file./usr/share/zoneinfo/โ The system timezone database directory./usr/share/zoneinfo/posixrulesโ When aTZstring includes adsttimezone without anything following it, then this file is used for thestart/endrules. It is in thetzfile(5)format. By default, the zoneinfo Makefile hard links it to theAmerica/New_Yorktzfile.
Above are the current standard file locations, but they are configurable when glibc is compiled. So like, your distro might've done something else. iykyk. ๐
๐ ATTRIBUTES ๐
For an explanation of the terms used in this section, see attributes(7).
tzset()โ Thread safety:MT-Safe env locale
(Original page had this in a cute little table, but we're keeping it as a bullet, mwah.)
โญ STANDARDS โญ
POSIX.1-2024. ๐
๐ธ HISTORY ๐ธ
tzset(),tznameโ POSIX.1-1988, SVr4, 4.3BSD.timezone,daylightโ POSIX.1-2001 (XSI), SVr4, 4.3BSD.
And here's some lore for you: 4.3BSD had a function
char *timezone(zone, dst)
that returned the name of the timezone corresponding to its first argument (minutes West of UTC). If the second argument was 0, the standard name was used, otherwise the daylight saving time version. Vintage icon behavior. ๐
๐จ CAVEATS ๐จ
Because the values of tzname, timezone, and daylight are often unspecified, and accessing them can lead to undefined behavior in multithreaded applications, code should instead obtain the time zone offset and abbreviations from the tm_gmtoff and tm_zone members of the broken-down time structure tm(3type).
Do not touch those globals in a threaded program. It's giving "I like to live dangerously" and we are NOT doing that today. Usetm_gmtoffandtm_zone. Periodt. ๐
๐ BUGS ๐
Since this function does not report errors, there's no way to know if the value of TZ represents a valid time zone. That's it. That's the bug. It just shrugs at you. ๐ญ
๐ซถ SEE ALSO ๐ซถ
date(1), gettimeofday(2), time(2), ctime(3), getenv(3), tzfile(5)
okay and that's the whole page, bestie, you're officially a time zone girlie now ๐โจ๐ฆ
This one's from Linux man-pages 6.20, dated 2026-02-08. Go forth and TZ responsibly. ๐๐
๐ฆ where this page comes from
- arch rolling: man-pages 6.20-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- ๐ the page's license: Linux-man-pages-copyleft
- Copyright 1993, David Metcalfe <david@prism.demon.co.uk>
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms