timespec_get - Man Page

ISO C interface to clock and time functions

Library

Standard C library (libc-lc),

Synopsis

#include <time.h>

int timespec_get(struct timespec *res, int base);
int timespec_getres(struct timespec *tp, int base);

Description

The timespec_get() function stores the current time, based on the specified time base, in the timespec(3type) structure pointed to by res.

The timespec_getres() function stores the resolution of times retrieved by timespec_get() with the specified time base in the timespec(3type) structure pointed to by tp, if tp is non-NULL. For a particular time base, the resolution is constant for the lifetime of the calling process.

TIME_UTC is always a supported time base, and is the only time base supported on Linux. The time and resolution in this time base are the same as those retrieved by clock_gettime(CLOCK_REALTIME, res) and clock_getres(CLOCK_REALTIME, tp), respectively. Other systems may support additional time bases.

Return Value

timespec_get() returns the nonzero base if it is a supported time base and the current time was successfully retrieved, or 0 otherwise.

timespec_getres() returns the nonzero base if it is a supported time base, or 0 otherwise.

Attributes

For an explanation of the terms used in this section, see attributes(7).

InterfaceAttributeValue
timespec_get(), timespec_getres()Thread safetyMT-Safe

Standards

timespec_get()
TIME_UTC

C23 (though ISO C doesn't specify the time epoch), POSIX.1-2024.

timespec_getres()

C23.

History

timespec_get()
TIME_UTC

C11, POSIX.1-2024, glibc 2.16, musl 1.1.10.

timespec_getres()

C23, glibc 2.34.

See Also

clock_gettime(2), clock_getres(2)

Referenced By

The man page timespec_getres(3) is an alias of timespec_get(3).

2025-02-10 Linux man-pages 6.13