1TIME(2) Linux Programmer's Manual TIME(2)
2
3
4
6 time - get time in seconds
7
9 #include <time.h>
10
11 time_t time(time_t *tloc);
12
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
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 appropriately.
23
25 EFAULT tloc points outside your accessible address space (but see
26 BUGS).
27
28 On systems where the C library time() wrapper function invokes
29 an implementation provided by the vdso(7) (so that there is no
30 trap into the kernel), an invalid address may instead trigger a
31 SIGSEGV signal.
32
34 SVr4, 4.3BSD, C89, C99, POSIX.1-2001. POSIX does not specify any error
35 conditions.
36
38 POSIX.1 defines seconds since the Epoch using a formula that approxi‐
39 mates the number of seconds between a specified time and the Epoch.
40 This formula takes account of the facts that all years that are evenly
41 divisible by 4 are leap years, but years that are evenly divisible by
42 100 are not leap years unless they are also evenly divisible by 400, in
43 which case they are leap years. This value is not the same as the
44 actual number of seconds between the time and the Epoch, because of
45 leap seconds and because system clocks are not required to be synchro‐
46 nized to a standard reference. The intention is that the interpreta‐
47 tion of seconds since the Epoch values be consistent; see POSIX.1-2008
48 Rationale A.4.15 for further rationale.
49
50 On Linux, a call to time() with tloc specified as NULL cannot fail with
51 the error EOVERFLOW, even on ABIs where time_t is a signed 32-bit inte‐
52 ger and the clock ticks past the time 2**31 (2038-01-19 03:14:08 UTC,
53 ignoring leap seconds). (POSIX.1 permits, but does not require, the
54 EOVERFLOW error in the case where the seconds since the Epoch will not
55 fit in time_t.) Instead, the behavior on Linux is undefined when the
56 system time is out of the time_t range. Applications intended to run
57 after 2038 should use ABIs with time_t wider than 32 bits.
58
60 Error returns from this system call are indistinguishable from success‐
61 ful reports that the time is a few seconds before the Epoch, so the C
62 library wrapper function never sets errno as a result of this call.
63
64 The tloc argument is obsolescent and should always be NULL in new code.
65 When tloc is NULL, the call cannot fail.
66
67 C library/kernel differences
68 On some architectures, an implementation of time() is provided in the
69 vdso(7).
70
72 date(1), gettimeofday(2), ctime(3), ftime(3), time(7), vdso(7)
73
75 This page is part of release 5.04 of the Linux man-pages project. A
76 description of the project, information about reporting bugs, and the
77 latest version of this page, can be found at
78 https://www.kernel.org/doc/man-pages/.
79
80
81
82Linux 2017-09-15 TIME(2)