time(2)
๐ time(2) โ bestie, it's literally clock o'clock ๐
okay so you're in the System Calls Manual section, page time(2), and we're about to get the current time in seconds like it's the easiest thing in the world (because it kinda is?? slay).
โจ NAME โจ
time โ get time in seconds ๐โจ
๐ LIBRARY ๐
Standard C library โ that's libc, link it with -lc ๐
๐ธ SYNOPSIS ๐ธ
#include <time.h>
time_t time(time_t *_Nullable tloc);
that's it. that's the whole function. so demure. so mindful. ๐
๐ฆ DESCRIPTION ๐ฆ
time() gives you back the time as the number of seconds since the Epoch โ and the Epoch, for the record, is 1970-01-01 00:00:00 +0000 (UTC). yes bestie, the Unix birthday. iconic behavior. ๐
If tloc is non-NULL, the return value is also stored in the memory pointed to by tloc. like, it gives you the answer and writes it down for you. overachiever energy fr fr ๐
โญ RETURN VALUE โญ
On success, you get the value of time in seconds since the Epoch. crowned. ๐
On error, ((time_t) -1) comes back, and errno is set to tell you what went wrong. ๐ญ
๐ ERRORS ๐
EOVERFLOWโ the time cannot be represented as atime_tvalue. this can happen if an executable with 32-bittime_tis run on a 64-bit kernel when the time is2038-01-19 03:14:08 UTCor later. (yes, that date. the y2k38 moment.) however, when the system time is out oftime_trange in other situations, the behavior is undefined โ so like, don't. ๐EFAULTโtlocpoints outside your accessible address space (but see BUGS below, it's giving nuance). On systems where the C librarytime()wrapper function invokes an implementation provided byvdso(7)โ so there's no trap into the kernel โ an invalid address may instead trigger aSIGSEGVsignal. no cap. ๐ฅ
๐ VERSIONS ๐
POSIX.1 defines "seconds since the Epoch" 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. Linux systems normally follow the POSIX requirement that this value ignore leap seconds, so that conforming systems interpret it consistently โ see POSIX.1-2018 Rationale A.4.16 if you wanna go read the receipts. ๐
Applications intended to run after 2038 should use ABIs with time_t wider than 32 bits; see time_t(3type). future-proofing is self care bestie ๐ง
๐ง C library/kernel differences
On some architectures, an implementation of time() is provided in the vdso(7). sneaky fast. we love her. โจ
๐ STANDARDS ๐
C11, POSIX.1-2024. certified. โจ
๐ HISTORY ๐
SVr4, 4.3BSD, C89, POSIX.1-2001, V7. she's been around longer than your fave has been relevant. respect the elders. ๐
๐ BUGS ๐
Error returns from this system call are indistinguishable from successful reports that the time is a few seconds before the Epoch โ so the C library wrapper function never sets errno as a result of this call. that's not a quirk, that's just how she is. ๐ญ
The tloc argument is obsolescent and should always be NULL in new code. let the girl retire. ๐ซถ
When tloc is NULL, the call cannot fail. periodt. ๐
๐ฅ SEE ALSO ๐ฅ
date(1), gettimeofday(2), ctime(3), ftime(3), time(7), vdso(7)
and that's the whole page, bestie!! go forth and grab timestamps responsibly ๐ธ๐ฆ
this masterpiece came to you from Linux man-pages 6.20, dated 2026-02-08, and it's the time(2) page ๐ luv u, bye!! โจ๐๐
๐ฆ where this page comes from
- arch rolling: man-pages 6.20-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- ๐ the page's license: Linux-man-pages-copyleft
- Copyright 1992, Drew Eckhardt <drew@cs.colorado.edu>
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms