man-pages/man3/tzset.3.html
2021-03-31 01:06:50 +01:00

335 lines
8.7 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of TZSET</TITLE>
</HEAD><BODY>
<H1>TZSET</H1>
Section: Linux Programmer's Manual (3)<BR>Updated: 2017-09-15<BR><A HREF="#index">Index</A>
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
tzset, tzname, timezone, daylight - initialize time conversion information
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
<PRE>
<B>#include &lt;<A HREF="file:///usr/include/time.h">time.h</A>&gt;</B>
<B>void tzset (void);</B>
<B>extern char *</B><I>tzname</I><B>[2];</B>
<B>extern long </B><I>timezone</I><B>;</B>
<B>extern int </B><I>daylight</I><B>;</B>
</PRE>
<P>
Feature Test Macro Requirements for glibc (see
<B><A HREF="/cgi-bin/man/man2html?7+feature_test_macros">feature_test_macros</A></B>(7)):
<P>
<B>tzset</B>():
_POSIX_C_SOURCE
<BR>
<I>tzname</I>:
_POSIX_C_SOURCE
<BR>
<I>timezone</I>,
<I>daylight</I>:
_XOPEN_SOURCE
<BR>&nbsp;&nbsp;&nbsp;&nbsp;||&nbsp;/*&nbsp;Glibc&nbsp;since&nbsp;2.19:&nbsp;*/&nbsp;_DEFAULT_SOURCE
<BR>&nbsp;&nbsp;&nbsp;&nbsp;||&nbsp;/*&nbsp;Glibc&nbsp;versions&nbsp;&lt;=&nbsp;2.19:&nbsp;*/&nbsp;_SVID_SOURCE
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>
The
<B>tzset</B>()
function initializes the <I>tzname</I> variable from the
<B>TZ</B>
environment variable.
This function is automatically called by the
other time conversion functions that depend on the timezone.
In a System-V-like environment, it will also set the variables <I>timezone</I>
(seconds West of UTC) and <I>daylight</I> (to 0 if this timezone does not
have any daylight saving time rules, or to nonzero if there is a time,
past, present or future when daylight saving time applies).
<P>
If the
<B>TZ</B>
variable does not appear in the environment, the system timezone is used.
The system timezone is configured by copying, or linking, a file in the
<B><A HREF="/cgi-bin/man/man2html?5+tzfile">tzfile</A></B>(5)
format to
<I>/etc/localtime</I>.
A timezone database of these files may be located in the system
timezone directory (see the <B>FILES</B> section below).
<P>
If the
<B>TZ</B>
variable does appear in the environment, but its value is empty,
or its value cannot be interpreted using any of the formats specified
below, then Coordinated Universal Time (UTC) is used.
<P>
The value of
<B>TZ</B>
can be one of two formats.
The first format is a string of characters that directly represent the
timezone to be used:
<P>
<I>std offset</I>[<I>dst</I>[<I>offset</I>][,<I>start</I>[<I>/time</I>],<I>end</I>[<I>/time</I>]]]
<P>
There are no spaces in the specification.
The <I>std</I> string specifies an abbreviation for the timezone and must be
three or more alphabetic characters.
When enclosed between the less-than (&lt;) and greater-than (&gt;) signs, the
characters set is expanded to include the plus (+) sign, the minus (-)
sign, and digits.
The <I>offset</I> string immediately
follows <I>std</I> and specifies the time value to be added to the local
time to get Coordinated Universal Time (UTC).
The <I>offset</I> is positive
if the local timezone is west of the Prime Meridian and negative if it is
east.
The hour must be between 0 and 24, and the minutes and seconds 00 and 59:
<P>
[<I>+</I>|<I>-</I>]<I>hh</I>[<I>:mm</I>[<I>:ss</I>]]
<P>
The <I>dst</I> string and <I>offset</I> specify the name and offset for the
corresponding daylight saving timezone.
If the offset is omitted,
it defaults to one hour ahead of standard time.
<P>
The <I>start</I> field specifies when daylight saving time goes into
effect and the <I>end</I> field specifies when the change is made back to
standard time.
These fields may have the following formats:
<DL COMPACT>
<DT id="1">J<I>n</I><DD>
This specifies the Julian day with <I>n</I> between 1 and 365.
Leap days are not counted.
In this format, February 29 can't be represented;
February 28 is day 59, and March 1 is always day 60.
<DT id="2"><I>n</I>
<DD>
This specifies the zero-based Julian day with <I>n</I> between 0 and 365.
February 29 is counted in leap years.
<DT id="3">M<I>m</I>.<I>w</I>.<I>d</I><DD>
This specifies day <I>d</I> (0 &lt;= <I>d</I> &lt;= 6) of week <I>w</I>
(1 &lt;= <I>w</I> &lt;= 5) of month <I>m</I> (1 &lt;= <I>m</I> &lt;= 12).
Week 1 is
the first week in which day <I>d</I> occurs and week 5 is the last week
in which day <I>d</I> occurs.
Day 0 is a Sunday.
</DL>
<P>
The <I>time</I> fields specify when, in the local time currently in effect,
the change to the other time occurs.
If omitted, the default is 02:00:00.
<P>
Here is 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 the first Sunday in October to the third Sunday in March,
and the changeovers happen at the default time of 02:00:00:
TZ=&quot;NZST-12:00:00NZDT-13:00:00,M10.1.0,M3.3.0&quot;
<P>
The second format specifies that the timezone information should be read
from a file:
<P>
:[filespec]
<P>
If the file specification <I>filespec</I> is omitted, or its value cannot
be interpreted, then Coordinated Universal Time (UTC) is used.
If <I>filespec</I> is given, it specifies another
<B><A HREF="/cgi-bin/man/man2html?5+tzfile">tzfile</A></B>(5)-format
file to read the timezone information from.
If <I>filespec</I> does not begin with a '/', the file specification is
relative to the system timezone directory.
If the colon is omitted each
of the above <B>TZ</B> formats will be tried.
<P>
Here's an example, once more for New Zealand:
<P>
TZ=&quot;:Pacific/Auckland&quot;
<A NAME="lbAE">&nbsp;</A>
<H2>ENVIRONMENT</H2>
<DL COMPACT>
<DT id="4"><B>TZ</B>
<DD>
If this variable is set its value takes precedence over the system
configured timezone.
<DT id="5"><B>TZDIR</B>
<DD>
If this variable is set its value takes precedence over the system
configured timezone database directory path.
</DL>
<A NAME="lbAF">&nbsp;</A>
<H2>FILES</H2>
<DL COMPACT>
<DT id="6"><I>/etc/localtime</I>
<DD>
The system timezone file.
<DT id="7"><I>/usr/share/zoneinfo/</I>
<DD>
The system timezone database directory.
<DT id="8"><I>/usr/share/zoneinfo/posixrules</I>
<DD>
When a TZ string includes a dst timezone without anything following it,
then this file is used for the start/end rules.
It is in the
<B><A HREF="/cgi-bin/man/man2html?5+tzfile">tzfile</A></B>(5)
format.
By default, the zoneinfo Makefile hard links it to the
<I>America/New_York</I> tzfile.
</DL>
<P>
Above are the current standard file locations, but they are
configurable when glibc is compiled.
<A NAME="lbAG">&nbsp;</A>
<H2>ATTRIBUTES</H2>
For an explanation of the terms used in this section, see
<B><A HREF="/cgi-bin/man/man2html?7+attributes">attributes</A></B>(7).
<TABLE BORDER>
<TR VALIGN=top><TD><B>Interface</B></TD><TD><B>Attribute</B></TD><TD><B>Value</B><BR></TD></TR>
<TR VALIGN=top><TD>
<B>tzset</B>()
</TD><TD>Thread safety</TD><TD>MT-Safe env locale<BR></TD></TR>
</TABLE>
<A NAME="lbAH">&nbsp;</A>
<H2>CONFORMING TO</H2>
POSIX.1-2001, POSIX.1-2008, SVr4, 4.3BSD.
<A NAME="lbAI">&nbsp;</A>
<H2>NOTES</H2>
<P>
4.3BSD had a function
<B>char *timezone(</B><I>zone</I><B>, </B><I>dst</I><B>)</B>
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.
<A NAME="lbAJ">&nbsp;</A>
<H2>SEE ALSO</H2>
<B><A HREF="/cgi-bin/man/man2html?1+date">date</A></B>(1),
<B><A HREF="/cgi-bin/man/man2html?2+gettimeofday">gettimeofday</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?2+time">time</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?3+ctime">ctime</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+getenv">getenv</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?5+tzfile">tzfile</A></B>(5)
<A NAME="lbAK">&nbsp;</A>
<H2>COLOPHON</H2>
This page is part of release 5.05 of the Linux
<I>man-pages</I>
project.
A description of the project,
information about reporting bugs,
and the latest version of this page,
can be found at
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT id="9"><A HREF="#lbAB">NAME</A><DD>
<DT id="10"><A HREF="#lbAC">SYNOPSIS</A><DD>
<DT id="11"><A HREF="#lbAD">DESCRIPTION</A><DD>
<DT id="12"><A HREF="#lbAE">ENVIRONMENT</A><DD>
<DT id="13"><A HREF="#lbAF">FILES</A><DD>
<DT id="14"><A HREF="#lbAG">ATTRIBUTES</A><DD>
<DT id="15"><A HREF="#lbAH">CONFORMING TO</A><DD>
<DT id="16"><A HREF="#lbAI">NOTES</A><DD>
<DT id="17"><A HREF="#lbAJ">SEE ALSO</A><DD>
<DT id="18"><A HREF="#lbAK">COLOPHON</A><DD>
</DL>
<HR>
This document was created by
<A HREF="/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:05:59 GMT, March 31, 2021
</BODY>
</HTML>