Section: POSIX Programmer's Manual (3P)
This manual page is part of the POSIX Programmer's Manual.
The Linux implementation of this interface may differ (consult
the corresponding Linux manual page for details of Linux behavior),
or the interface may not be implemented on Linux.
--- get time
time_t time(time_t *tloc);
The functionality described on this reference page is aligned with the
ISO C standard. Any conflict between the requirements described here and the
ISO C standard is unintentional. This volume of POSIX.1-2017 defers to the ISO C standard.
function shall return the value of time
in seconds since the Epoch.
argument points to an area where the return value is also stored. If
is a null pointer, no value is stored.
Upon successful completion,
shall return the value of time. Otherwise, (time_t
)-1 shall be
function may fail if:
The number of seconds since the Epoch will not fit in an object of type
The following sections are informative.
Getting the Current Time
The following example uses the
function to calculate the time elapsed, in seconds, since the Epoch,
to convert that value to a broken-down time, and
to convert the broken-down time values into a printable string.
result = time(NULL);
printf("%s%ju secs since the Epoch\n",
This example writes the current time to
in a form like this:
Wed Jun 26 10:32:15 1996
835810335 secs since the Epoch
Timing an Event
The following example gets the current time, prints it out in the
user's format, and prints the number of minutes to an event being
minutes_to_event = ...;
printf("The time is ");
printf("There are %d minutes to the event.\n",
function returns a value in seconds while
(seconds and nanoseconds) and
(seconds and microseconds), respectively, and are therefore capable of
returning more precise times. The
function is also capable of more precision than
as it returns a value in clock ticks, although it returns the elapsed time
since an arbitrary point such as system boot time, not since the epoch.
Implementations in which
is a 32-bit signed integer (many historical implementations) fail in
the year 2038. POSIX.1-2008 does not address this problem. However, the use
type is mandated in order to ease the eventual fix.
On some systems the
function is implemented using a system call that does not return an
error condition in addition to the return value. On these systems it is
impossible to differentiate between valid and invalid return values and
hence overflow conditions cannot be reliably detected.
The use of the
header instead of
allows compatibility with the ISO C standard.
Many historical implementations (including Version 7) and the 1984 /usr/group standard use
This volume of POSIX.1-2017 uses the latter type in order to agree with the ISO C standard.
In a future version of this volume of POSIX.1-2017,
is likely to be required to be capable of representing times far in the
future. Whether this will be mandated as a 64-bit type or a requirement
that a specific date in the future be representable (for example, 10000
AD) is not yet determined. Systems purchased after the approval of this volume of POSIX.1-2017
should be evaluated to determine whether their lifetime will extend
The Base Definitions volume of POSIX.1-2017,
Portions of this text are reprinted and reproduced in electronic form
from IEEE Std 1003.1-2017, Standard for Information Technology
-- Portable Operating System Interface (POSIX), The Open Group Base
Specifications Issue 7, 2018 Edition,
Copyright (C) 2018 by the Institute of
Electrical and Electronics Engineers, Inc and The Open Group.
In the event of any discrepancy between this version and the original IEEE and
The Open Group Standard, the original IEEE and The Open Group Standard
is the referee document. The original Standard can be obtained online at
Any typographical or formatting errors that appear
in this page are most likely
to have been introduced during the conversion of the source files to
man page format. To report such errors, see