time module
Time primitives — millisecond and nanosecond clocks, calendar component conversions, duration math, and ISO 8601 formatting.
Time is represented as milliseconds since the Unix epoch.
import "time" as time;
var now = time.now();
print(time.iso(now)); // 2026-05-11T14:30:00.000Z
print(time.components(now, false)); // { year, month, day, hour, ... }
Clocks
| Function | Description |
|---|---|
time.now() → number | Current time, milliseconds since epoch. |
time.now_seconds() → number | Same as now() / 1000. |
time.now_ns() → number | High-resolution monotonic nanosecond counter. |
Calendar conversion
| Function | Description |
|---|---|
time.components(ms, local) → map | {year, month, day, hour, minute, second, ms, weekday, yearday}. local selects local vs. UTC. |
time.from(parts, local) → number | Inverse of components. |
time.local_offset_ms(ms) → number | Local timezone offset from UTC at that instant. |
Duration helpers (durations are plain numbers in ms)
| Function | Description |
|---|---|
time.seconds(n), time.minutes(n), time.hours(n), time.days(n) | Convert a count to milliseconds. |
time.add_seconds(ms, n), add_minutes, add_hours, add_days | Shift an instant by a duration. |
ISO 8601
| Function | Description |
|---|---|
time.iso(ms) → string | UTC, 2026-05-11T14:30:00.000Z. |
time.iso_local(ms) → string | Local with offset, 2026-05-11T20:30:00.000+06:00. |
time.parse_iso(s) → number | Parse an ISO 8601 string back to a timestamp. |