OPENSSL\_GMTIME(3ossl) OpenSSL OPENSSL\_GMTIME(3ossl)

# [NAME](#NAME)

OPENSSL\_gmtime, OPENSSL\_gmtime\_adj, OPENSSL\_gmtime\_diff, OPENSSL\_timegm, OPENSSL\_posix\_to\_tm, OPENSSL\_tm\_to\_posix - platform-agnostic OpenSSL time routines

# [SYNOPSIS](#SYNOPSIS)

```
 #include <openssl/crypto.h>
 struct tm *OPENSSL_gmtime(const time_t *timer, struct tm *result);
 int OPENSSL_gmtime_adj(struct tm *tm, int offset_day, long offset_sec);
 int OPENSSL_gmtime_diff(int *pday, int *psec,
                        const struct tm *from, const struct tm *to);
 #include <openssl/posix_time.h>
 int OPENSSL_timegm(const struct tm *tm, time_t *out_time);
 int OPENSSL_posix_to_tm(int64_t time, struct tm *out_tm);
 int OPENSSL_tm_to_posix(struct tm t_tm, int64_t *out);
```

# [DESCRIPTION](#DESCRIPTION)

**OPENSSL\_gmtime()** returns the Unix/Posix time specified by *timer* into the provided *result* argument. |timer| must be a value of the number of seconds relative to 0 hours, 0 minutes, 0 seconds, January 1, 1970, Coordinated Universal Time, without including leap seconds, and must be in the range of the year 0 to 9999 inclusively. *result* will be zeroed, and only the fields *tm\_year*, *tm\_mon*, *tm\_mday*, *tm\_hour*, *tm\_min*, and *tm\_sec* will be updated in *result* on success.

**OPENSSL\_gmtime\_adj()** adds the offsets in *offset\_day* and *offset\_sec* to *tm*.

**OPENSSL\_gmtime\_diff()** calculates the difference between *from* and *to*.

**OPENSSL\_timegm()** converts a time structure in UTC time in *tm* to a time\_t value in *out\_time*.

**OPENSSL\_posix\_to\_tm()** converts a int64\_t POSIX time value in *time*, to a broken out time value in *tm*. *time* must be a value of the number of seconds relative to 0 hours, 0 minutes, 0 seconds, January 1, 1970, Coordinated Universal Time, without including leap seconds, and must be in the range of the year 0 to 9999 inclusively. *tm* will be zeroed, and only the fields *tm\_year*, *tm\_mon*, *tm\_mday*, *tm\_hour*, *tm\_min*, and *tm\_sec* will be updated in *tm* on success.

**OPENSSL\_tm\_to\_posix()** converts a time value between the years 0 and 9999 in *tm* to a POSIX time value in *out*.

# [NOTES](#NOTES)

These functions are intended for use when using *struct tm* values converted from ASN1\_TIME values. They are not intended for general purpose time conversions, and should not be used for other purposes.

When these functions use a *struct tm* as input, they consider only the *tm\_year*, *tm\_mon*, *tm\_mday*, *tm\_hour*, *tm\_min*, and *tm\_sec* fields of the structure, all other fields are ignored. Out of range values, including leap seconds, are not permitted.

**OPENSSL\_gmtime\_adj()** converts *tm* into a days and seconds value, adds *offset\_day* and *offset\_sec* to the values, and then converts back into a *struct tm* specified by *tm*.

It is an error to call **OPENSSL\_gmtime()** with *result* equal to NULL. The contents of the time\_t given by *timer* are stored into the *result*. Calling with *timer* equal to NULL means use the current time.

**OPENSSL\_gmtime\_adj()** converts *tm* into a days and seconds value, adds the offsets, then converts back into a *struct tm* specified by *tm*.

**OPENSSL\_gmtime\_diff()** calculates the difference between the two *struct tm* structures *from* and *to*. The difference in days is placed into *\*pday*, the remaining seconds are placed to *\*psec*. The value in *\*psec* will be less than the number of seconds per day (86400).

# [RETURN VALUES](#RETURN_VALUES)

**OPENSSL\_gmtime()** returns *result* on success or NULL for failure. It can fail if the input time is outside of the range of year 0 to 9999.

**OPENSSL\_posix\_to\_tm()** return 1 for success or 0 on failure. It can fail if the input time is outside of the range of year 0 to 9999.

**OPENSSL\_timegm()** and **OPENSSL\_tm\_to\_posix()** return 1 for success or 0 for failure. **OpenSSL\_timegm()** can fail it the time is not representable in a time\_t, and both may fail on invalid or out of range input in the input tm.

**OPENSSL\_gmtime\_adj()** and **OPENSSL\_gmtime\_diff()** return 0 on error, and 1 on success.

# [BUGS](#BUGS)

**OPENSSL\_gmtime()** and **OPENSSL\_timegm()** are not platform-agnostic due to possible limitations in the range of the platform *time\_t* type. **OPENSSL\_posix\_to\_tm()** and **OPENSSL\_tm\_to\_posix()** provide similar functionality in a platform independent manner.

# [HISTORY](#HISTORY)

**OPENSSL\_gmtime()** returns NULL on error, or *result* on success.

**OPENSSL\_gmtime()**, **OPENSSL\_gmtime\_adj()** and **OPENSSL\_gmtime\_diff()** have been in OpenSSL since 1.0.0. **OPENSSL\_timegm()**, **OPENSSL\_posix\_to\_tm()** and **OPENSSL\_tm\_to\_posix()** were originally from BoringSSL and have been in OpenSSL since 4.0.0

# [COPYRIGHT](#COPYRIGHT)

Copyright 2022 The OpenSSL Project Authors. All Rights Reserved.

Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at &lt;https://www.openssl.org/source/license.html&gt;.

2026-09-29 4.0.3

---

Document: OPENSSL_tm_to_posix(3ossl) from openssl-4.0 4.0.3-r6 (Chainguard OS)
