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 a time_t value. this can happen if an executable with 32-bit time_t is run on a 64-bit kernel when the time is 2038-01-19 03:14:08 UTC or later. (yes, that date. the y2k38 moment.) however, when the system time is out of time_t range in other situations, the behavior is undefined โ€” so like, don't. ๐Ÿ™ˆ
  • EFAULT โ€” tloc points outside your accessible address space (but see BUGS below, it's giving nuance). On systems where the C library time() wrapper function invokes an implementation provided by vdso(7) โ€” so there's no trap into the kernel โ€” an invalid address may instead trigger a SIGSEGV signal. 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
  • ๐Ÿ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms