Standard library
Time
Wall clock, sleep, monotonic clock, and format/parse.
Introduction
Wall clock, sleep, monotonic clock, and format/parse. Import std/time to bind the module as time. Call free functions as time.name(...). Struct methods use a receiver value.
/ std/time
This page is the package reference for std/time. Private helpers used only by co-located tests are not listed.
Functions
Free functions on time. Each function has a short description, an example, then parameters and return shape.
now_ms
Wall-clock milliseconds since the Unix epoch. Call form: time.now_ms().
/ std/time
$ t = time.now_ms()
Parameters: No parameters. Returns: Integer milliseconds.
sleep_ms
Sleeps at least ms milliseconds. When ms is zero or negative, the call returns immediately. Call form: time.sleep_ms(ms).
/ std/time
time.sleep_ms(1)
Parameters: ms: milliseconds to sleep. Returns: None.
mono_ms
Monotonic milliseconds since process start (not wall clock). Useful for measuring intervals. Call form: time.mono_ms().
/ std/time
$ result = time.mono_ms()
Parameters: No parameters. Returns: Value produced by the call (see description).
format
Formats wall milliseconds with a pattern string. Call form: time.format(ms, fmt).
/ std/time
$ s = time.format(0, "%Y")
Parameters: ms: wall milliseconds since epoch. fmt: format pattern string. Returns: Formatted time string.
parse
Parses a time string with a format pattern. Call form: time.parse(s, fmt).
/ std/time
| time.parse("1970", "%Y") {
$ ms { }
! e { }
}Parameters: s: text to parse. fmt: format pattern string. Returns: Result. Ok arm: wall milliseconds. Err arm: parse failure.