---
name: "pmtimespecNow"
section: "3"
platform: "linux"
package: "pcp"
version: "7.2.2-2"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/pmtimespecNow"
---

# pmtimespecNow(3)

helper routines for time stored as a struct timespec

## NAME

**pmtimespecNow**, **pmtimespecInc**, **pmtimespecDec**, **pmtimespecAdd**, **pmtimespecSub**, **pmtimespecToReal**, **pmtimespecFromReal**, **pmtimespecTotimeval**, **pmtimespecPrint**, **pmtimespecPrintInterval** - helper routines for time stored as a struct timespec

## C SYNOPSIS

**#include \<pcp/pmapi.h\>**

**void pmtimespecNow(struct timespec \****tp***);**\
 **void pmtimespecInc(struct timespec \****ap***, const struct timespec \****bp***);**\
 **void pmtimespecDec(struct timespec \****ap***, const struct timespec \****bp***);**\
 **double pmtimespecAdd(const struct timespec \****ap***,** **const struct timespec \****bp***);**\
 **double pmtimespecSub(const struct timespec \****ap***,** **const struct timespec \****bp***);**\
 **double pmtimespecToReal(const struct timespec \****tp***);**\
 **void pmtimespecFromReal(double** *secs***, struct timespec \****tp***);**\
 **void pmtimespecTotimeval(struct timespec \****tsp,* **struct timeval \****tvp***);**\
 **void pmtimespecPrint(FILE \****f***, const struct timespec \****tp***);**\
 **void pmtimespecPrintInterval(FILE \****f***, const struct timespec \****tp***);**

**cc ... -lpcp**

## DESCRIPTION

**pmtimespecNow** is a platform-independent method that returns the current system time since the Epoch in *tp*.

**pmtimespecInc** adds the time in *ap* to the time in *bp* and stores the result in *ap*. Similarly **pmtimespecDec** subtracts the time in *bp* from the time in *ap* and stores the result in *ap*.

**pmtimespecAdd** (and **pmtimespecSub**) add (and subtract) times and return the result as a double value. The time in the *ap* argument is not changed.

**pmtimespecToReal** converts the time in *tp* to an equivalent double value. **pmtimespecFromReal** provides the reverse conversion, taking the time in *secs* and returning the equivalent time in *tp*.

**pmtimespecTotimeval** converts the struct timespec *tsp* into an equivalent struct timeval *tvp* (modulo nanosecond to microsecond truncation).

For **pmtimespecAdd**, **pmtimespecSub**, **pmtimespecToReal** and **pmtimespecFromReal** there is an issue of numerical precision. If the **double** result or operand has more than 6 decimal digits of precision in the seconds part of the value, then the fractional value is converted to microseconds before arithmetic computations, so the nanoseconds field is only accurate to 6 decimal digits in this case.

**pmtimespecPrint** prints the timestamp from *tp* on the stream *f* in the local time (as returned by [**pmLocaltime**(3)](/pmLocaltime/3.md)) in the format HH:MM:SS.XXXXXXXXX.

**pmtimespecPrintInterval** prints the interval from *tp* on the stream *f* in a minimalist format \[\[HH**h**\]MM**m**\]SS\[.XXXXXXXXX\]**s** where the hours, minutes and nanoseconds are only reported if they are non-zero, and any trailing zeroes in the nanoseconds are omitted. For example if tp-\>tv\_sec was 75 and tp-\>tv\_nsec was 51000000 then the output would be **1h15.51s**.

## NOTES

For variants of these interfaces using microsecond precision and the timeval structure, refer to [**pmtimevalNow**(3)](/pmtimevalNow/3.md).

## COMPATIBILITY

Prior to PCP 7.0 the routine **pmtimespecPrint** was called **pmPrintHighResStamp**. To support PMAPI transition, the old routine can still be used if applications are recompiled with **-DPMAPI\_VERSION=2**.

**pmPrintHighResStamp** is now deprecated and compile-time support for this routine name will be removed in a future release.

## SEE ALSO

[**PMAPI**(3)](/PMAPI/3.md), [**pmLocaltime**(3)](/pmLocaltime/3.md) and [**pmtimevalNow**(3)](/pmtimevalNow/3.md).
