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 πŸ“–)

InterfaceAttributeValue
timelocal(), timegm()Thread safetyMT-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:

The timelocal() function is equivalent to the POSIX standard function mktime(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
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms