man-pages/man2/time.2.html
2021-03-31 01:06:50 +01:00

206 lines
5.0 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of TIME</TITLE>
</HEAD><BODY>
<H1>TIME</H1>
Section: Linux Programmer's Manual (2)<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>
time - get time in seconds
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
<B>#include &lt;<A HREF="file:///usr/include/time.h">time.h</A>&gt;</B>
<P>
<B>time_t time(time_t *</B><I>tloc</I><B>);</B>
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>
<B>time</B>()
returns the time as the number of seconds since the
Epoch, 1970-01-01 00:00:00 +0000 (UTC).
<P>
If
<I>tloc</I>
is non-NULL,
the return value is also stored in the memory pointed to by
<I>tloc</I>.
<A NAME="lbAE">&nbsp;</A>
<H2>RETURN VALUE</H2>
On success, the value of time in seconds since the Epoch is returned.
On error, <I>((time_t)&nbsp;-1)</I> is returned, and <I>errno</I> is set
appropriately.
<A NAME="lbAF">&nbsp;</A>
<H2>ERRORS</H2>
<DL COMPACT>
<DT id="1"><B>EFAULT</B>
<DD>
<I>tloc</I>
points outside your accessible address space (but see BUGS).
<DT id="2"><DD>
On systems where the C library
<B>time</B>()
wrapper function invokes an implementation provided by the
<B><A HREF="/cgi-bin/man/man2html?7+vdso">vdso</A></B>(7)
(so that there is no trap into the kernel),
an invalid address may instead trigger a
<B>SIGSEGV</B>
signal.
</DL>
<A NAME="lbAG">&nbsp;</A>
<H2>CONFORMING TO</H2>
SVr4, 4.3BSD, C89, C99, POSIX.1-2001.
POSIX does not specify any error conditions.
<A NAME="lbAH">&nbsp;</A>
<H2>NOTES</H2>
POSIX.1 defines
<I>seconds since the Epoch</I>
using a formula that approximates the number of seconds between a
specified time and the Epoch.
This formula takes account of the facts that
all years that are evenly divisible by 4 are leap years,
but years that are evenly divisible by 100 are not leap years
unless they are also evenly divisible by 400,
in which case they are leap years.
This value is not the same as the actual number of seconds between the time
and the Epoch, because of leap seconds and because system clocks are not
required to be synchronized to a standard reference.
The intention is that the interpretation of seconds since the Epoch values be
consistent; see POSIX.1-2008 Rationale A.4.15 for further rationale.
<P>
On Linux, a call to
<B>time</B>()
with
<I>tloc</I>
specified as NULL cannot fail with the error
<B>EOVERFLOW</B>,
even on ABIs where
<I>time_t</I>
is a signed 32-bit integer and the clock ticks past the time 2**31
(2038-01-19 03:14:08 UTC, ignoring leap seconds).
(POSIX.1 permits, but does not require, the
<B>EOVERFLOW</B>
error in the case where the seconds since the Epoch will not fit in
<I>time_t</I>.)
Instead, the behavior on Linux is undefined when the system time is out of the
<I>time_t</I>
range.
Applications intended to run after 2038 should use ABIs with
<I>time_t</I>
wider than 32 bits.
<A NAME="lbAI">&nbsp;</A>
<H2>BUGS</H2>
Error returns from this system call are indistinguishable from
successful reports that the time is a few seconds
<I>before</I>
the Epoch, so the C library wrapper function never sets
<I>errno</I>
as a result of this call.
<P>
The
<I>tloc</I>
argument is obsolescent and should always be NULL in new code.
When
<I>tloc</I>
is NULL, the call cannot fail.
<A NAME="lbAJ">&nbsp;</A>
<H3>C library/kernel differences</H3>
On some architectures, an implementation of
<B>time</B>()
is provided in the
<B><A HREF="/cgi-bin/man/man2html?7+vdso">vdso</A></B>(7).
<A NAME="lbAK">&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?3+ctime">ctime</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+ftime">ftime</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?7+time">time</A></B>(7),
<B><A HREF="/cgi-bin/man/man2html?7+vdso">vdso</A></B>(7)
<A NAME="lbAL">&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="3"><A HREF="#lbAB">NAME</A><DD>
<DT id="4"><A HREF="#lbAC">SYNOPSIS</A><DD>
<DT id="5"><A HREF="#lbAD">DESCRIPTION</A><DD>
<DT id="6"><A HREF="#lbAE">RETURN VALUE</A><DD>
<DT id="7"><A HREF="#lbAF">ERRORS</A><DD>
<DT id="8"><A HREF="#lbAG">CONFORMING TO</A><DD>
<DT id="9"><A HREF="#lbAH">NOTES</A><DD>
<DT id="10"><A HREF="#lbAI">BUGS</A><DD>
<DL>
<DT id="11"><A HREF="#lbAJ">C library/kernel differences</A><DD>
</DL>
<DT id="12"><A HREF="#lbAK">SEE ALSO</A><DD>
<DT id="13"><A HREF="#lbAL">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:35 GMT, March 31, 2021
</BODY>
</HTML>