TIME.H(7) Miscellaneous Information Manual TIME.H(7)

time.htime types

#include <time.h>

[CX] Some of the functionality described on this reference page extends the ISO C standard. Applications shall define the appropriate feature test macro (see XSH V2_chap02(3)) to enable the visibility of these symbols in this header.

The <time.h> header shall define the , , , types as described in <sys/types.h>.

[CX] 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>.

[CX] The tag sigevent shall be declared as naming an incomplete structure type, the contents of which are described in the <signal.h> header.

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 Saving flag.
long        tm_gmtoff Seconds east of UTC.
const char *tm_zone   Timezone abbreviation.

When tm_isdst is set by an interface defined in this standard, its value shall be positive if Daylight Saving Time (DST) is in effect and 0 if DST is not in effect. [CX] It shall not be set to a negative value by any interface defined in this standard. When tm_isdst is passed to the mktime(3) function, it specifies how mktime(3) is to handle DST when calculating the time since the Epoch value; see mktime(3).

[CX] If the value of tm_zone is accessed after the value of is subsequently modified, and the tm_zone value was not set by a call to gmtime(3) or gmtime_r(3), the behavior is undefined.

The <time.h> header shall declare the structure, which shall include at least the following members:

time_t  tv_sec    Whole seconds.
long    tv_nsec   Nanoseconds [0, 999999999].

[CX] The <time.h> header shall also declare the 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:

As described in <stddef.h> .
A number used to convert the value returned by the () function into seconds. The value shall be an expression with type clock_t . [XSI] The value of CLOCKS_PER_SEC shall be 1 million on XSI-conformant systems. However, it may be variable on other systems, and it should not be assumed that CLOCKS_PER_SEC is a compile-time constant.
An integer constant greater than 0 that designates the UTC time base in calls to () . The value shall be suitable for use in #if preprocessing directives.

[CX] The <time.h> header shall define the following symbolic constants. The values shall have a type that is assignment-compatible with clockid_t.

[CX]
The identifier for the system-wide monotonic clock, which is defined as a clock measuring real time, whose value cannot be set via () and which cannot have negative clock jumps. The maximum possible clock jump shall be implementation-defined.
[CPT]
The identifier of the CPU-time clock associated with the process making a clock* () or timer* () function call.
[CX] The identifier of the system-wide clock measuring real time.
[TCT]
The identifier of the CPU-time clock associated with the thread making a clock* () or timer* () function call.

[CX] The <time.h> header shall define the following symbolic constant:

Flag indicating time is absolute. For functions taking timer objects, this refers to the clock associated with the timer.

The <time.h> header shall provide a declaration or definition for getdate_err. The getdate_err symbol shall expand to an expression of type . 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.

The following shall be declared as functions and may also be defined as macros. Function prototypes shall be provided.

[OB]
char      *asctime(const struct tm *);

clock_t    clock(void);
[CPT]
int        clock_getcpuclockid(pid_t, clockid_t *);

[CX]
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 *);

[OB]
char      *ctime(const time_t *);

double     difftime(time_t, time_t);
[XSI]
struct tm *getdate(const char *);

struct tm *gmtime(const time_t *);
[CX]
struct tm *gmtime_r(const time_t *restrict, struct tm *restrict);

struct tm *localtime(const time_t *);
[CX]
struct tm *localtime_r(const time_t *restrict, struct tm *restrict);

time_t     mktime(struct tm *);
[CX]
int        nanosleep(const struct timespec *, struct timespec *);

size_t     strftime(char *restrict, size_t, const char *restrict,
           const struct tm *restrict);
[CX]
size_t     strftime_l(char *restrict, size_t, const char *restrict,
               const struct tm *restrict, locale_t);

[XSI]
char      *strptime(const char *restrict, const char *restrict,
               struct tm *restrict);

time_t     time(time_t *);
[CX]
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);

int        timespec_get(struct timespec *, int);
[CX]
void       tzset(void);

The <time.h> header shall declare the following as variables:

[XSI]
extern int    daylight;
extern long   timezone;

[CX]
extern char  *tzname[];

[CX] Inclusion of the <time.h> header may make visible all symbols from the <signal.h> header.

The range [0,60] for allows for the occasional leap second.

is a signed value; therefore, years before 1900 may be represented.

To obtain the number of clock ticks per second returned by the times(3) function, applications should call (_SC_CLK_TCK).

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.

None.

<locale.h>, <signal.h>, <stddef.h>, <sys/types.h>

XSH V2_chap02(3), asctime(3), clock(3), clock_getcpuclockid(3), clock_getres(3), clock_nanosleep(3), ctime(3), difftime(3), futimens(3), getdate(3), gmtime(3), localtime(3), mktime(3), mq_receive(3), mq_send(3), nanosleep(3), pthread_getcpuclockid(3), pthread_mutex_clocklock(3), pthread_rwlock_clockrdlock(3), pthread_rwlock_clockwrlock(3), sem_clockwait(3), strftime(3), strptime(3), sysconf(3), time(3), timer_create(3), timer_delete(3), timer_getoverrun(3), timespec_get(3), tzset(3)

First released in Issue 1. Derived from Issue 1 of the SVID.

The DESCRIPTION is updated for alignment with the POSIX Realtime Extension and the POSIX Threads Extension.

The Open Group Corrigendum U035/6 is applied. In the DESCRIPTION, the types clockid_t and timer_t have been described.

The following changes are made for alignment with the ISO POSIX-1:1996 standard:

  • The POSIX timer-related functions are marked as part of the Timers option.

The symbolic name CLK_TCK is removed. Application usage is added describing how its equivalent functionality can be obtained using sysconf(3).

The clock_getcpuclockid(3) function and manifest constants CLOCK_PROCESS_CPUTIME_ID and CLOCK_THREAD_CPUTIME_ID are added for alignment with IEEE Std 1003.1d-1999.

The manifest constant CLOCK_MONOTONIC and the clock_nanosleep(3) function are added for alignment with IEEE Std 1003.1j-2000.

The following changes are made for alignment with the ISO/IEC 9899:1999 (“ISO C99”) standard:

IEEE PASC Interpretation 1003.1 #84 is applied adding the statement that symbols from the <signal.h> header may be made visible when the <time.h> header is included.

Extensions beyond the ISO C standard are marked.

Austin Group Interpretation 1003.1-2001 #111 is applied.

SD5-XBD-ERN-74 is applied.

The strftime_l(3) function is added from The Open Group Technical Standard, 2006, Extended API Set Part 4.

Functionality relating to the Timers option is moved to the Base.

This reference page is clarified with respect to macros and symbolic constants, and declarations for the locale_t and pid_t types and the sigevent structure are added.

The description of the getdate_err value is expanded.

POSIX.1-2008, Technical Corrigendum 1, XBD/TC1-2008/0076 [212] and XBD/TC1-2008/0077 [212] are applied.

Austin Group Defect 1253 is applied, changing "Daylight Savings" to "Daylight Saving".

Austin Group Defect 1302 is applied, aligning this header with the ISO/IEC 9899:2018 standard.

Austin Group Defect 1346 is applied, requiring support for Monotonic Clock.

Austin Group Defect 1410 is applied, removing the asctime_r () and () functions.

Austin Group Defect 1533 is applied, adding and tm_zone to the tm structure.

Austin Group Defect 1597 is applied, changing clock(3) to () in the descriptions of CLOCK_PROCESS_CPUTIME_ID and CLOCK_THREAD_CPUTIME_ID.

Austin Group Defect 1614 is applied, clarifying the requirements for the tm_isdst member of the tm structure.

June 14, 2024 posix.fail