Skip to content

std.time

std.time

The std.time module provides access to the current runtime clock and basic sleep control.

Import

import std.time as time

API

FunctionSignatureDescription
now_msfunc now_ms() -> i64Current time in milliseconds since epoch
sleep_msfunc sleep_ms(ms: i64)Pause the current thread for at least ms milliseconds

Example

import std.time as time
func main() -> i32:
let t = time.now_ms()
return 0

now_ms returns i64. There is no string.from_i64 in the current standard library, so printing a timestamp directly is not supported without an intermediate cast. To compare timestamps, use arithmetic:

Timing elapsed duration

import std.time as time
func main() -> i32:
let start = time.now_ms()
let i: i32 = 0
while (i < 1000000):
i = i + 1
let elapsed = time.now_ms() - start
if (elapsed > 0):
return 0
return 1

Sleeping

import std.time as time
func main() -> i32:
let start = time.now_ms()
time.sleep_ms(25)
let elapsed = time.now_ms() - start
if (elapsed >= 10):
return 0
return 1

Full reference

FunctionSignatureDescription
now_msfunc now_ms() -> i64milliseconds since epoch
sleep_msfunc sleep_ms(ms: i64)sleep for at least ms milliseconds