Skip to content

Time Module

The std/time module provides time manipulation utilities including timestamps, formatting, sleeping, and date components.

import { time } from "std/time"

Returns the current Unix timestamp in seconds.

const ts = time.now()
println(ts) // e.g. 1719504000

Alias for time.now(). Returns the current Unix timestamp.

const ts = time.unix()

Pauses execution asynchronously for the given number of milliseconds.

println("Wait...")
await time.sleep(1000) // Sleep for 1 second
println("Done!")

time.format(timestamp: int, layout: string): string

Section titled “time.format(timestamp: int, layout: string): string”

Formats a timestamp to a string using the given layout.

const formatted = time.format(time.now(), "2006-01-02 15:04:05")
println(formatted) // e.g. "2025-06-27 14:30:00"

time.parse(str: string, layout: string): int

Section titled “time.parse(str: string, layout: string): int”

Parses a date string into a Unix timestamp using the given layout.

const ts = time.parse("2025-06-27", "2006-01-02")
println(ts)

Formats a timestamp as an ISO 8601 string.

const iso = time.toISO(time.now())
println(iso) // e.g. "2025-06-27T14:30:00Z"

Returns the number of seconds elapsed since the given timestamp.

const start = time.now()
// ... do some work ...
const elapsed = time.since(start)
println("Took " + elapsed + " seconds")

Returns the current date as an object with year, month, day, hour, minute, and second fields.

const d = time.date()
println(d["year"]) // e.g. 2025
println(d["month"]) // e.g. 6
println(d["day"]) // e.g. 27
println(d["hour"]) // e.g. 14
println(d["minute"]) // e.g. 30
println(d["second"]) // e.g. 0

Returns the current year.

Returns the current month (1–12).

Returns the current day of the month.

println(time.year()) // 2025
println(time.month()) // 6
println(time.day()) // 27
FunctionDescription
time.now()Current Unix timestamp (seconds)
time.unix()Alias for now()
time.sleep(ms)Async sleep for milliseconds
time.format(ts, layout)Format timestamp to string
time.parse(str, layout)Parse string to timestamp
time.toISO(ts)Format as ISO 8601
time.since(ts)Seconds elapsed since timestamp
time.date()Current date as object
time.year()Current year
time.month()Current month (1–12)
time.day()Current day of month
import { time } from "std/time"
const start = time.now()
// Simulate work
await time.sleep(2000)
const elapsed = time.since(start)
println("Operation took " + elapsed + " seconds")