The Open Group Base Specifications Issue 6
IEEE Std 1003.1, 2003 Edition
Copyright © 2001-2003 The IEEE and The Open Group, All Rights reserved.

NAME

time.h - time types

SYNOPSIS

#include <time.h>

DESCRIPTION

[CX] [Option Start] Some of the functionality described on this reference page extends the ISO C standard. Applications shall define the appropriate feature test macro (see the System Interfaces volume of IEEE Std 1003.1-2001, Section 2.2, The Compilation Environment) to enable the visibility of these symbols in this header. [Option End]

The <time.h> header shall declare the structure tm, 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.

The <time.h> header shall define the following symbolic names:

NULL
Null pointer constant.
CLOCKS_PER_SEC
A number used to convert the value returned by the clock() function into seconds.
CLOCK_PROCESS_CPUTIME_ID
[TMR|CPT] [Option Start]
The identifier of the CPU-time clock associated with the process making a clock() or timer*() function call. [Option End]
CLOCK_THREAD_CPUTIME_ID
[TMR|TCT] [Option Start]
The identifier of the CPU-time clock associated with the thread making a clock() or timer*() function call. [Option End]

[TMR] [Option Start] The <time.h> header shall declare the structure timespec, which has 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 has at least the following members:

struct timespec  it_interval  Timer period. 
struct timespec  it_value     Timer expiration. 

The following manifest constants shall be defined:

CLOCK_REALTIME
The identifier of the system-wide realtime clock.
TIMER_ABSTIME
Flag indicating time is absolute. For functions taking timer objects, this refers to the clock associated with the timer. [Option End]
CLOCK_MONOTONIC
[MON] [Option Start]
The identifier for the system-wide monotonic clock, which is defined as a clock whose value cannot be set via clock_settime() and which cannot have backward clock jumps. The maximum possible clock jump shall be implementation-defined. [Option End]

The clock_t, size_t, time_t, [TMR] [Option Start] clockid_t, and timer_t [Option End] types shall be defined as described in <sys/types.h> .

[XSI] [Option Start] Although the value of CLOCKS_PER_SEC is required to be 1 million on all XSI-conformant systems, it may be variable on other systems, and it should not be assumed that CLOCKS_PER_SEC is a compile-time constant. [Option End]

[XSI] [Option Start] The <time.h> header shall provide a declaration for getdate_err. [Option End]

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

char      *asctime(const struct tm *);
[TSF][Option Start]
char      *asctime_r(const struct tm *restrict, char *restrict);
[Option End]
clock_t    clock(void);
[CPT][Option Start]
int        clock_getcpuclockid(pid_t, clockid_t *);
[Option End]
[TMR][Option Start]
int        clock_getres(clockid_t, struct timespec *);
int        clock_gettime(clockid_t, struct timespec *);
[Option End]
[CS][Option Start]
int        clock_nanosleep(clockid_t, int, const struct timespec *,
               struct timespec *);
[Option End]
[TMR][Option Start]
int        clock_settime(clockid_t, const struct timespec *);
[Option End]
char      *ctime(const time_t *);
[TSF][Option Start]
char      *ctime_r(const time_t *, char *);
[Option End]
double     difftime(time_t, time_t);
[XSI][Option Start]
struct tm *getdate(const char *);
[Option End]
struct tm *gmtime(const time_t *);
[TSF][Option Start]
struct tm *gmtime_r(const time_t *restrict, struct tm *restrict);
[Option End]
struct tm *localtime(const time_t *);
[TSF][Option Start]
struct tm *localtime_r(const time_t *restrict, struct tm *restrict);
[Option End]
time_t     mktime(struct tm *);
[TMR][Option Start]
int        nanosleep(const struct timespec *, struct timespec *);
[Option End]
size_t     strftime(char *restrict, size_t, const char *restrict,
           const struct tm *restrict);
[XSI][Option Start]
char      *strptime(const char *restrict, const char *restrict,
               struct tm *restrict);
[Option End]
time_t     time(time_t *);
[TMR][Option Start]
int        timer_create(clockid_t, struct sigevent *restrict,
               timer_t *restrict);
int        timer_delete(timer_t);
int        timer_gettime(timer_t, struct itimerspec *);
int        timer_getoverrun(timer_t);
int        timer_settime(timer_t, int, const struct itimerspec *restrict,
               struct itimerspec *restrict);
[Option End]
[CX][Option Start]
void       tzset(void);
[Option End]


The following shall be declared as variables:

[XSI][Option Start]
extern int    daylight;
extern long   timezone;
[Option End]
[CX][Option Start]
extern char  *tzname[];
[Option End]

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


The following sections are informative.

APPLICATION USAGE

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

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

To obtain the number of clock ticks per second returned by the times() function, applications should call sysconf(_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 previous versions of POSIX.

FUTURE DIRECTIONS

None.

SEE ALSO

<signal.h> , <sys/types.h> , the System Interfaces volume of IEEE Std 1003.1-2001, asctime(), clock(), clock_getcpuclockid(), clock_getres(), clock_nanosleep(), ctime(), difftime(), getdate(), gmtime(), localtime(), mktime(), nanosleep(), strftime(), strptime(), sysconf(), time(), timer_create(), timer_delete(), timer_getoverrun(), tzname, tzset(), utime()

CHANGE HISTORY

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

Issue 5

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

Issue 6

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 symbolic name CLK_TCK is removed. Application usage is added describing how its equivalent functionality can be obtained using sysconf().

The clock_getcpuclockid() 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() function are added for alignment with IEEE Std 1003.1j-2000.

The following changes are made for alignment with the ISO/IEC 9899:1999 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.

End of informative text.


UNIX ® is a registered Trademark of The Open Group.
POSIX ® is a registered Trademark of The IEEE.
[ Main Index | XBD | XCU | XSH | XRAT ]