Skip to content

os

The sandbox exposes exactly four os functions — time only. Verified absent: os.execute, os.getenv, os.remove, os.rename, os.exit, os.tmpname, os.setlocale, os.difftime-anything-else. There is no process, environment, or filesystem access from mods.

High-resolution CPU time consumed by the process, in seconds. This is the canonical clock for measuring elapsed time inside a mod — it’s what the execution budget itself uses.

local started = os.clock()
usems.hook("frame", function()
if os.clock() - started >= 1.0 then
print("one second of process time elapsed")
end
end)

Seconds since the Unix epoch (UTC). With a table, interprets that calendar date (isdst ignored; fields are treated as UTC).

local now = os.time()
print(type(now)) --> number
local portal_release = os.time({
year = 2007, month = 10, day = 10, hour = 12,
})
print(portal_release) --> 1192014400

Seconds between two os.time values (t2 - t1).

local start = os.time()
-- ...later:
print(os.difftime(os.time(), start)) --> e.g. 42
-- days since Portal shipped:
local release = os.time({year = 2007, month = 10, day = 10})
print(math.floor(os.difftime(os.time(), release) / 86400))

Formats a timestamp (default: now) as a string. Prefix the format with ! for UTC; *t returns a table of components instead.

print(os.date("!%Y-%m-%d %H:%M", os.time())) --> 2026-08-26 19:30
print(os.date("!%d.%m.%Y")) --> 26.08.2026
local parts = os.date("!*t")
print(parts.year, parts.hour) --> 2026 19

Common format codes:

Code Meaning Example
%Y %m %d year, month, day 2026 08 26
%H %M %S hour, minute, second 19 30 05
%j day of year 238
%A %B weekday, month name Wednesday August
%p am/pm PM