timespec_get(3)

timespec_get3

Get current calendar time

Usage

#include <time.h>

int

timespec_get(struct timespec *ts, int base);

Library

Standard C Library (libc, -lc)

Overview

The timespec_get function sets the interval pointed to by ts to hold the current calendar time based on the specified time base in base.

The base TIME_UTC returns the time since the epoch. This time is expressed in seconds and nanoseconds since midnight (0 hour), January 1, 1970. In FreeBSD, this corresponds to CLOCK_REALTIME.

The base TIME_MONOTONIC returns a monotonically-increasing time since an unspecified point in the past. In FreeBSD, this corresponds to CLOCK_MONOTONIC.

Return values

The timespec_get function returns the passed value of base if successful, otherwise 0 on failure.

Releases

20 releases since FreeBSD 12.0-RELEASE; the text changed 8 times.

  1. 12.0
  2. 12.1
  3. 12.2
  4. 12.3
  5. 12.4
  6. 13.0–13.2
  7. 13.3–13.5
  8. 14.0–15.0
  9. 15.1–16.0

Standards

The timespec_get function with a base of TIME_UTC conforms to ISO/IEC 9899:2011 (“ISO C11”). The TIME_MONOTONIC base conforms to ISO/IEC 9899:2024 (“ISO C23”).

History

This interface first appeared in FreeBSD 12.

Authors

Kamil Rytarowski ⟨[email protected]⟩ Warner Losh ⟨[email protected]⟩

From base 16.0-CURRENT-20261027-61c70dc16a79 in FreeBSD 16.0-CURRENT (2026-10-27). Parsed by carta from the page's mdoc source.