TIME(3am)
β¨ TIME(3am) β¨ β the gawk time extension, bestie edition π
okay so real quick: this is TIME(3am) from the GNU Awk Extension Modules, and it's literally the cutest little trio of time functions you ever did see. clock in, bestie, we're doing time stuff π°οΈβ¨
πΈ NAME πΈ
time β time functions for gawk π«Ά
π SYNOPSIS π
@load "time"
time = gettimeofday()
ret = sleep(amount)
timeval = strptime(string, format)
π DESCRIPTION π
So the time extension adds three functions, and their names are gettimeofday(), sleep(), and strptime(), and here's the tea on each one π
gettimeofday()β this one hands you the number of seconds since the Epoch as a floating-point value, and it should have subsecond precision, so you're getting the fancy fractional drama β¨. If something goes wrong it returns-1and setsERRNOto tell you what the problem is. no cap.sleep(seconds)β this one attempts to sleep for however many seconds you hand it, and yes,secondsmay include a fractional portion, so2.5is totally valid, go off ππ€. Ifsecondsis negative, or if the attempt to sleep fails, then it returns-1and setsERRNO. Otherwise it should return0after it's done snoozing for the indicated amount of time. iconic behaviour.strptime()β this one takes two arguments: a string representing a date and time, and a format string describing the data in that string. It calls the C librarystrptime(3)function with the given values. If the parsing succeeds, the results get passed to the C librarymktime(3)function, and its result is what comes back to you β expressing the time in seconds since the epoch in the current local timezone, regardless of any timezone specified in the string arguments. (This is the same as gawk's built-insystime()function, iykyk.) Otherwise it returns-1upon error, and in that latter case,ERRNOindicates the problem π.
π BUGS π
Okay so the underlying strptime(3) C library routine apparently just... ignores any time zone indication in the date string?? and produces values relative to the current time zone instead π. The manpage literally says it might be better to have this routine return a string similar to what gawk's mktime() function expects, but β and I quote the vibe β we ran out of energy. honestly? felt. π
π EXAMPLE π
@load "time"
...
printf "It is now %g seconds since the Epoch\n", gettimeofday()
...
printf "Pausing for a while... " ; sleep(2.5) ; print "done"
...
format = "%b %d %H:%M:%S %Z %Y"
now = systime()
print now, "<" (result = strftime(format, now)) ">",
then = strptime(result, format)
print strftime(format, then)
π SEE ALSO π
GAWK: Effective AWK Programming, and the man pages for the other extensions shipped with gawk π¦gettimeofday(2),nanosleep(2),select(2), andstrptime(3)β
π«Ά AUTHOR π«Ά
Arnold Robbins, arnold@skeeve.com. π
π COPYING PERMISSIONS π
Copyright Β© 2012, 2013, 2018, 2022, 2023, 2024, 2026, Free Software Foundation, Inc. Copyright Β© 2019, Arnold David Robbins.
Permission is granted to make and distribute verbatim copies of this manual page provided the copyright notice and this permission notice are preserved on all copies.
Permission is granted to copy and distribute modified versions of this manual page under the conditions for verbatim copying, provided that the entire resulting derived work is distributed under the terms of a permission notice identical to this one.
Permission is granted to copy and distribute translations of this manual page into another language, under the above conditions for modified versions, except that this permission notice may be stated in a translation approved by the Foundation.
and that's the whole page, bestie!! π§π brought to you by the Free Software Foundation, dated Feb 25 2026, and it's TIME(3am) β go forth and timestamp everything, periodt. β¨π
π¦ where this page comes from
- arch rolling: gawk 5.4.1-1 Β· GPL-3.0-or-later
- nixos 26.05: gawk-interactive 5.4.1
- nixpkgs unstable: gawk 5.4.1
- nixpkgs unstable: gawk-interactive 5.4.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms