---
name: "timespec_get"
section: "3"
platform: "macos"
package: "Libc"
version: "1752.120.2"
release: "macOS 26.5"
platforms: ["linux", "freebsd", "macos"]
url: "https://new.carta.tech/timespec_get"
---

# timespec\_get(3)

get current calendar time

## NAME

**timespec\_get** – get current calendar time

## LIBRARY

Standard C Library (libc, -lc)

## SYNOPSIS

**#include \<time.h\>**

*int*\

**timespec\_get**(*struct timespec \*ts*, *int base*);

## DESCRIPTION

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. This corresponds to CLOCK\_REALTIME.

## RETURN VALUES

The **timespec\_get** function returns the passed value of *base* if successful, otherwise 0 on failure.

## SEE ALSO

[gettimeofday(2)](/gettimeofday/2.md), [clock\_gettime(2)](/clock_gettime/2.md), [time(3)](/time/3.md)

## STANDARDS

The **timespec\_get** function with a *base* of TIME\_UTC conforms to ISO/IEC 9899:2011 (“ISO C11”).

## AUTHORS

Kamil Rytarowski ⟨*kamil@NetBSD.org*⟩ Warner Losh ⟨*imp@FreeBSD.org*⟩
