This project was created because I wanted Lua developers to experience the same simplicity and power of Python’s built‑in time module. The goal of this library is to give you function names, behaviors, inputs, and outputs identical to Python’s time module`, but fully implemented in pure Lua, working on all operating systems.
If you know Python’s time, then you already know this module.
You can install this module with LuaRocks forever.
luarocks install luatimeThe module must be required exactly like Python with one difference just in its name:
local luatime = require("luatime")All function names and parameters match Python’s time module.
Returns the current time in seconds since the epoch (UNIX timestamp).
local now = luatime.time()
print(now)Pauses execution for the given number of seconds.
luatime.sleep(2)
print("2 seconds passed")Returns a clock value that always increases. Cannot go backward.
local t1 = luatime.monotonic()
luatime.sleep(1)
local t2 = luatime.monotonic()
print(t2 - t1)High‑precision performance timer (alias of monotonic).
local t = luatime.perf_counter()
for i = 1, 1e6 do end
print(luatime.perf_counter() - t)Returns CPU time used by the program.
local t = luatime.process_time()
for i = 1, 5e6 do end
print(luatime.process_time() - t)Converts a timestamp to a human‑readable string.
print(luatime.ctime())
print(luatime.ctime(0))Returns a table representing the local time.
local t = luatime.localtime()
print(t.year, t.month, t.day)Returns a table representing UTC time.
local t = luatime.gmtime()
print(t.hour)Converts a time table back into a timestamp.
local ts = luatime.mktime{year=2025, month=1, day=1, hour=0}
print(ts)Formats a time structure into a string.
print(luatime.strftime("%Y-%m-%d %H:%M:%S", luatime.localtime()))| Python Function | Lua Function | Same Behavior |
|---|---|---|
| time() | luatime.time() | ✔️ |
| sleep() | luatime.sleep() | ✔️ |
| monotonic() | luatime.monotonic() | ✔️ |
| perf_counter() | luatime.perf_counter() | ✔️ |
| process_time() | luatime.process_time() | ✔️ |
| ctime() | luatime.ctime() | ✔️ |
| localtime() | luatime.localtime() | ✔️ |
| gmtime() | luatime.gmtime() | ✔️ |
| mktime() | luatime.mktime() | ✔️ |
| strftime() | luatime.strftime() | ✔️ |
This library exists so that developers who already know Python’s time can use identical functions in Lua. My goal was to make your transition between languages easier, cleaner, and more enjoyable.