timegm(3)
β¨ timegm(3) β bestie edition β¨
okay so you know how gmtime and localtime take a timestamp and break it down into a cute little struct? yeah. these are the glow-up in reverse π
Manual name: timegm β and its bestie timelocal. π
πΈ NAME πΈ
timegm, timelocal β the inverses of gmtime and localtime, fr fr
π LIBRARY π
Standard C library (libc, -lc) β she's standard, she's iconic, she's everywhere. π
π SYNOPSIS π
#include <time.h>
[[deprecated]] time_t timelocal(struct tm *tm);
time_t timegm(struct tm *tm);
π¦ Feature Test Macro Requirements for glibc (see feature_test_macros(7)): π¦
timelocal(), timegm():
- Since glibc 2.19:
_DEFAULT_SOURCE
- glibc 2.19 and earlier:
_BSD_SOURCE || _SVID_SOURCE
lowkey read the feature test macros page if you want the deets, bestie β feature_test_macros(7) has you covered π«Ά
π DESCRIPTION π
So timelocal() and timegm() are literally the inverses of localtime(3) and gmtime(3). They're doing the reverse dance. πΊ
Both of them take a broken-down time (you know, a struct tm with all the fields all spread out) and squish it back into calendar time β that's seconds since the Epoch, where the Epoch is 1970-01-01 00:00:00 +0000, UTC. the origin story of all time tbh β
The difference between the two? It's giving timezone drama:
timelocal()β takes the local timezone into account when doing the conversion πtimegm()β takes the input value to be Coordinated Universal Time (UTC) πβ¨
That's it. That's the whole vibe difference. Pick your girl wisely.
π₯ RETURN VALUE π₯
On success, these functions slay β they return the calendar time (seconds since the Epoch), expressed as a value of type time_t. π
On error, they return the value (time_t) -1 and set errno to indicate the error. π sadness.
π ERRORS π
EOVERFLOWβ bestie the result cannot be represented. it's too big. it does not fit. no cap. π«
π ATTRIBUTES π
For an explanation of the terms used in this section, see attributes(7). (iykyk π)
| Interface | Attribute | Value |
|---|---|---|
timelocal(), timegm() | Thread safety | MT-Safe env locale |
ok so it's honestly not a table girlie but the vibes are: timelocal() and timegm() are MT-Safe env locale. that's the whole table. periodt. β¨
π STANDARDS π
BSD. β she's a BSD original, respect the heritage π§
β HISTORY β
GNU, BSD. β that's the ancestry, that's the lineage, that's the family tree π«Ά
Also, and I cannot stress this enough:
Thetimelocal()function is equivalent to the POSIX standard functionmktime(3). There is no reason to ever use it.
fr fr. not me warning you off. mktime(3) does the same thing. just use that. π
(also she's [[deprecated]] up there in the synopsis, if you didn't catch it π)
πΈ SEE ALSO πΈ
that's a wrap bestie π this page came from Linux man-pages 6.20, dated 2026-02-08, and yes the manual really is called timegm(3). go forth and convert some broken-down time. you got this. πβ¨π
π¦ where this page comes from
- arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- π the page's license: Linux-man-pages-copyleft
- Copyright 2001, Andries E. Brouwer <aeb@cwi.nl>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms