TIME(3POSIX)
๐ TIME(3POSIX) โ bestie, it's time โจ
okay so real talk: this page is part of the POSIX Programmer's Manual ๐. And lowkey a warning before we even start โ the Linux implementation of this interface may differ (so pls go consult the corresponding Linux manual page for the deets on actual Linux behavior), or the interface might not even be implemented on Linux at all. ๐ Not me giving you homework on line one.
โจ NAME โจ
time โ get time โฐ
๐ธ SYNOPSIS ๐ธ
#include <time.h>
time_t time(time_t *tloc);
๐ DESCRIPTION ๐
So 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 (fr fr, nobody's trying to start drama). This volume of POSIX.1โ2017 defers to the ISO C standard. periodt.
The time() function shall return the value of time in seconds since the Epoch. โณ iconic behavior.
The tloc argument points to an area where the return value is also stored. If tloc is a null pointer, no value is stored. like, it's optional bestie, no pressure ๐
๐ซถ RETURN VALUE ๐ซถ
Upon successful completion, time() shall return the value of time. ๐
Otherwise, (time_t)-1 shall be returned. ๐ญ
๐ฅ ERRORS ๐ฅ
The time() function may fail if:
EOVERFLOWโ The number of seconds since the Epoch will not fit in an object of typetime_t. (the vibes are overflowing, and not in a cute way ๐ญ)
The following sections are informative. ๐ฆ
๐ EXAMPLES ๐
๐ธ Getting the Current Time ๐ธ
The following example uses the time() function to calculate the time elapsed, in seconds, since the Epoch, localtime() to convert that value to a broken-down time, and asctime() to convert the broken-down time values into a printable string. it's giving pipeline energy โจ
#include <stdio.h>
#include <time.h>
int main(void)
{
time_t result;
result = time(NULL);
printf("%s%ju secs since the Epoch\n",
asctime(localtime(&result)),
(uintmax_t)result);
return(0);
}
This example writes the current time to stdout 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 timed. main character scheduling energy, honestly ๐
#include <time.h>
#include <stdio.h>
...
time_t now;
int minutes_to_event;
...
time(&now);
minutes_to_event = ...;
printf("The time is ");
puts(asctime(localtime(&now)));
printf("There are %d minutes to the event.\n",
minutes_to_event);
...
๐ APPLICATION USAGE ๐
None. (literally nothing. we love a low-effort section ๐ )
๐ง RATIONALE ๐ง
The time() function returns a value in seconds while clock_gettime() and gettimeofday() return a struct timespec (seconds and nanoseconds) and struct timeval (seconds and microseconds), respectively, and are therefore capable of returning more precise times. So like, time() is the vibes-only version. The times() function is also capable of more precision than time() 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. (different starting line, bestie, don't get it twisted ๐)
Implementations in which time_t 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 of the time_t type is mandated in order to ease the eventual fix. (they're aware, they're just not fixing it yet. classic.)
On some systems the time() 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. ๐ญ so you literally cannot tell. no cap.
The use of the <time.h> header instead of <sys/types.h> allows compatibility with the ISO C standard. ๐
Many historical implementations (including Version 7) and the 1984 /usr/group standard use long instead of time_t. This volume of POSIX.1โ2017 uses the latter type in order to agree with the ISO C standard. (glow-up arc, we love to see it โจ)
๐ฎ FUTURE DIRECTIONS ๐ฎ
In a future version of this volume of POSIX.1โ2017, time_t 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 past 2038. ๐ fr fr check your receipts.
๐ SEE ALSO ๐
asctime(), clock(), clock_getres(), ctime(), difftime(), futimens(), gettimeofday(), gmtime(), localtime(), mktime(), strftime(), strptime(), times(), utime()
The Base Definitions volume of POSIX.1โ2017, <time.h>
๐ COPYRIGHT ๐
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 http://www.opengroup.org/unix/online.html .
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 https://www.kernel.org/doc/man-pages/reporting_bugs.html .
okay that's the whole page bestie, we ate and left no crumbs ๐
โจ this lil legend came to you courtesy of IEEE/The Open Group, 2017, and the page itself is TIME(3POSIX) โ mwah, take care of her ๐๐ฆ๐
๐ฆ where this page comes from
- debian bookworm: manpages-posix-dev 2017a-2 ยท Other
- debian trixie: manpages-posix-dev 2017a-2 ยท Other
- ubuntu jammy: manpages-posix-dev 2017a-2 ยท Other
- ubuntu noble: manpages-posix-dev 2017a-2 ยท Other
- ubuntu resolute: manpages-posix-dev 2017a-2build1 ยท Other
- ubuntu stonking: manpages-posix-dev 2017a-2.1 ยท Other
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms