1TIME(2)                    Linux Programmer's Manual                   TIME(2)
2
3
4

NAME

6       time - get time in seconds
7

SYNOPSIS

9       #include <time.h>
10
11       time_t time(time_t *tloc);
12

DESCRIPTION

14       time()  returns  the  time  as  the  number of seconds since the Epoch,
15       1970-01-01 00:00:00 +0000 (UTC).
16
17       If tloc is non-NULL, the return value is  also  stored  in  the  memory
18       pointed to by tloc.
19

RETURN VALUE

21       On  success,  the value of time in seconds since the Epoch is returned.
22       On error, ((time_t) -1) is returned, and errno is set to  indicate  the
23       error.
24

ERRORS

26       EFAULT tloc  points  outside  your  accessible  address  space (but see
27              BUGS).
28
29              On systems where the C library time() wrapper  function  invokes
30              an  implementation  provided by the vdso(7) (so that there is no
31              trap into the kernel), an invalid address may instead trigger  a
32              SIGSEGV signal.
33

CONFORMING TO

35       SVr4, 4.3BSD, C89, C99, POSIX.1-2001.  POSIX does not specify any error
36       conditions.
37

NOTES

39       POSIX.1 defines seconds since the Epoch using a formula  that  approxi‐
40       mates  the  number  of  seconds between a specified time and the Epoch.
41       This formula takes account of the facts that all years that are  evenly
42       divisible  by  4 are leap years, but years that are evenly divisible by
43       100 are not leap years unless they are also evenly divisible by 400, in
44       which  case they are leap years.  This value is not the same as the ac‐
45       tual number of seconds between the time and the Epoch, because of  leap
46       seconds  and  because system clocks are not required to be synchronized
47       to a standard reference.  The intention is that the  interpretation  of
48       seconds  since  the Epoch values be consistent; see POSIX.1-2008 Ratio‐
49       nale A.4.15 for further rationale.
50
51       On Linux, a call to time() with tloc specified as NULL cannot fail with
52       the error EOVERFLOW, even on ABIs where time_t is a signed 32-bit inte‐
53       ger and the clock reaches or exceeds 2**31 seconds (2038-01-19 03:14:08
54       UTC,  ignoring  leap seconds).  (POSIX.1 permits, but does not require,
55       the EOVERFLOW error in the case where the seconds since the Epoch  will
56       not  fit  in time_t.)  Instead, the behavior on Linux is undefined when
57       the system time is out of the time_t range.  Applications  intended  to
58       run after 2038 should use ABIs with time_t wider than 32 bits.
59

BUGS

61       Error returns from this system call are indistinguishable from success‐
62       ful reports that the time is a few seconds before the Epoch, so  the  C
63       library wrapper function never sets errno as a result of this call.
64
65       The tloc argument is obsolescent and should always be NULL in new code.
66       When tloc is NULL, the call cannot fail.
67
68   C library/kernel differences
69       On some architectures, an implementation of time() is provided  in  the
70       vdso(7).
71

SEE ALSO

73       date(1), gettimeofday(2), ctime(3), ftime(3), time(7), vdso(7)
74

COLOPHON

76       This  page  is  part of release 5.13 of the Linux man-pages project.  A
77       description of the project, information about reporting bugs,  and  the
78       latest     version     of     this    page,    can    be    found    at
79       https://www.kernel.org/doc/man-pages/.
80
81
82
83Linux                             2021-03-22                           TIME(2)
Impressum