time.h(7POSIX)
β¨ time.h β time types β¨
okay bestie so this is a page from the POSIX Programmer's Manual (like, the time.h(7POSIX) one, yes, the manual name is right there in the header, we're just folding it into the conversation like civilized people π
).
heads up, queen: this page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ (so go check the corresponding Linux manual page for the deets on Linux behavior), or honestly the interface might not even be implemented on Linux at all. no cap.
πΈ PROLOG πΈ
This manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ (consult the corresponding Linux manual page for details of Linux behavior), or the interface may not be implemented on Linux.
π NAME π
time.h β time types. that's it, that's the name, short and iconic π
β¨ SYNOPSIS β¨
#include <time.h>
π¦ DESCRIPTION π¦
okay so some of the functionality on this reference page is extending the ISO C standard (yes, going above and beyond, main character energy π). Applications shall define the appropriate feature test macro (peep the System Interfaces volume of POSIX.1β2017, Section 2.2, The Compilation Environment) to enable the visibility of these symbols in this header.
The <time.h> header shall define the clock_t, size_t, time_t types as described in <sys/types.h>.
The <time.h> header shall define the clockid_t and timer_t types as described in <sys/types.h>.
The <time.h> header shall define the locale_t type as described in <locale.h>.
The <time.h> header shall define the pid_t type as described in <sys/types.h>.
The tag sigevent shall be declared as naming an incomplete structure type β the contents of which are described in the <signal.h> header. it's giving mystery, it's giving β¨enigmaβ¨
The <time.h> header shall declare the tm structure, which shall include at least the following members:
int tm_sec Seconds [0,60].
int tm_min Minutes [0,59].
int tm_hour Hour [0,23].
int tm_mday Day of month [1,31].
int tm_mon Month of year [0,11].
int tm_year Years since 1900.
int tm_wday Day of week [0,6] (Sunday =0).
int tm_yday Day of year [0,365].
int tm_isdst Daylight Savings flag.
The value of tm_isdst shall be positive if Daylight Savings Time is in effect, 0 if Daylight Savings Time is not in effect, and negative if the information is not available. three moods, honestly relatable π
The <time.h> header shall declare the timespec structure, which shall include at least the following members:
time_t tv_sec Seconds.
long tv_nsec Nanoseconds.
The <time.h> header shall also declare the itimerspec structure, which shall include at least the following members:
struct timespec it_interval Timer period.
struct timespec it_value Timer expiration.
The <time.h> header shall define the following macros:
NULLβ As described in<stddef.h>. the og, the blueprint π«ΆCLOCKS_PER_SECβ A number used to convert the value returned by theclock()function into seconds. The value shall be an expression with typeclock_t. The value ofCLOCKS_PER_SECshall be 1 million on XSI-conformant systems. However, it may be variable on other systems, and it should not be assumed thatCLOCKS_PER_SECis a compile-time constant. β οΈ
The <time.h> header shall define the following symbolic constants. The values shall have a type that is assignment-compatible with clockid_t.
CLOCK_MONOTONICβ The identifier for the system-wide monotonic clock, which is defined as a clock measuring real time, whose value cannot be set viaclock_settime()and which cannot have negative clock jumps. The maximum possible clock jump shall be implementation-defined. no going backwards, bestie, we only move forward here π«CLOCK_PROCESS_CPUTIME_IDβ The identifier of the CPU-time clock associated with the process making aclock()ortimer*()function call.CLOCK_REALTIMEβ The identifier of the system-wide clock measuring real time. the classic βCLOCK_THREAD_CPUTIME_IDβ The identifier of the CPU-time clock associated with the thread making aclock()ortimer*()function call.
The <time.h> header shall define the following symbolic constant:
TIMER_ABSTIMEβ Flag indicating time is absolute. For functions taking timer objects, this refers to the clock associated with the timer. absolute, as in, no chill, no wiggle room, periodt.
The <time.h> header shall provide a declaration or definition for getdate_err. The getdate_err symbol shall expand to an expression of type int. It is unspecified whether getdate_err is a macro or an identifier declared with external linkage, and whether or not it is a modifiable lvalue. If a macro definition is suppressed in order to access an actual object, or a program defines an identifier with the name getdate_err, the behavior is undefined. π like genuinely undefined, do not test it.
The following shall be declared as functions and may also be defined as macros. Function prototypes shall be provided.
char *asctime(const struct tm *);
char *asctime_r(const struct tm *restrict, char *restrict);
clock_t clock(void);
int clock_getcpuclockid(pid_t, clockid_t *);
int clock_getres(clockid_t, struct timespec *);
int clock_gettime(clockid_t, struct timespec *);
int clock_nanosleep(clockid_t, int, const struct timespec *,
struct timespec *);
int clock_settime(clockid_t, const struct timespec *);
char *ctime(const time_t *);
char *ctime_r(const time_t *, char *);
double difftime(time_t, time_t);
struct tm *getdate(const char *);
struct tm *gmtime(const time_t *);
struct tm *gmtime_r(const time_t *restrict, struct tm *restrict);
struct tm *localtime(const time_t *);
struct tm *localtime_r(const time_t *restrict, struct tm *restrict);
time_t mktime(struct tm *);
int nanosleep(const struct timespec *, struct timespec *);
size_t strftime(char *restrict, size_t, const char *restrict,
const struct tm *restrict);
size_t strftime_l(char *restrict, size_t, const char *restrict,
const struct tm *restrict, locale_t);
char *strptime(const char *restrict, const char *restrict,
struct tm *restrict);
time_t time(time_t *);
int timer_create(clockid_t, struct sigevent *restrict,
timer_t *restrict);
int timer_delete(timer_t);
int timer_getoverrun(timer_t);
int timer_gettime(timer_t, struct itimerspec *);
int timer_settime(timer_t, int, const struct itimerspec *restrict,
struct itimerspec *restrict);
void tzset(void);
look at all those little guys, so many functions, we love a full roster π
The <time.h> header shall declare the following as variables:
extern int daylight;
extern long timezone;
extern char *tzname[];
Inclusion of the <time.h> header may make visible all symbols from the <signal.h> header. π surprise guests, iykyk
The following sections are informative.
π APPLICATION USAGE π
- The range
[0,60]fortm_secallows for the occasional leap second. a little extra second, as a treat πΈ tm_yearis a signed value; therefore, years before 1900 may be represented. yes we can go back in time, slay β³- To obtain the number of clock ticks per second returned by the
times()function, applications should callsysconf(_SC_CLK_TCK).
π RATIONALE π
The range [0,60] seconds allows for positive or negative leap seconds. The formal definition of UTC does not permit double leap seconds, so all mention of double leap seconds has been removed, and the range shortened from the former [0,61] seconds seen in earlier versions of this standard. character development fr, the glow-down nobody asked for but everyone needed π
π§ FUTURE DIRECTIONS π§
None.
nothing coming, no spoilers, we are at peace π¦
β SEE ALSO β
<locale.h>,<signal.h>,<stddef.h>,<sys_types.h>- The System Interfaces volume of POSIX.1β2017, Section 2.2, The Compilation Environment,
asctime(),clock(),clock_getcpuclockid(),clock_getres(),clock_nanosleep(),ctime(),difftime(),getdate(),gmtime(),localtime(),mktime(),mq_receive(),mq_send(),nanosleep(),pthread_getcpuclockid(),pthread_mutex_timedlock(),pthread_rwlock_timedrdlock(),pthread_rwlock_timedwrlock(),sem_timedwait(),strftime(),strptime(),sysconf(),time(),timer_create(),timer_delete(),timer_getoverrun(),tzset(),utime()
the whole friend group, go say hi to all of them π«Ά
π 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 .
and that's the whole page, bestie π IEEE/The Open Group dropped this in 2017, and you just read the entire time.h(7POSIX) situation. go forth and clock_gettime() responsibly β¨π
π¦ 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