time

Wall-clock access, sleep, stopwatch, and timestamp formatting.

Import

import time

Functions

time.now() -> float

Current Unix timestamp as a float (seconds since epoch).

time.now_ms() -> int

Current time in milliseconds since epoch.

time.clock() -> float

Monotonic clock value in seconds - use this for timing, not now(). Also available as time.monotonic().

time.millis() -> int

Current time in milliseconds (alias for now_ms).

time.sleep(secs: float)

Sleep the current thread for the given number of seconds. Accepts fractional values.

time.sleep_ms(ms: int)

Sleep for the given number of milliseconds.

time.stopwatch() -> map

Returns a stopwatch object with an elapsed() method that returns seconds since creation.

time.format(t: float, fmt: str) -> str

Format a Unix timestamp as a string using a strftime-style format string.

time.parse(s: str, fmt: str) -> float

Parse a formatted time string into a Unix timestamp.

Components

time.year(t), time.month(t), time.day(t), time.hour(t), time.minute(t), time.second(t) - extract individual components from a timestamp.

Examples

scratch.xs