time

std.chrono.time

rec Time

pub rec Time;

具有纳秒精度的绝对时间瞬间

sec:自 Unix 纪元(1970-01-01 00:00:00 UTC)以来的秒数 nsec:秒内的纳秒数 [0, 999999999]

fun now

pub fun now() Time;

返回当前的墙钟时间(wall-clock time)

ret:来自系统时钟的当前 Time,出错时返回零

fun monotonic

pub fun monotonic() Time;

返回当前的单调时钟时间

ret:来自单调时钟的当前 Time(用于测量流逝时间),出错时返回零

fun unix

pub fun unix(sec: i64, nsec: i64) Time;

从 Unix 时间戳创建一个 Time

sec:自 Unix 纪元以来的秒数 nsec:秒内的纳秒数 ret:将其 nsec 规范化为 [0, 999999999]Time

fun since

pub fun since(t: Time) Duration;

返回自 t 以来经过的时间

t:起始时间 ret:自 t 以来的持续时间

fun until

pub fun until(t: Time) Duration;

返回直到 t 为止的持续时间

t:目标时间 ret:直到 t 的持续时间

fun time_unix_sec

pub fun time_unix_sec(t: Time) i64;

返回自 Unix 纪元以来的秒数

t:要查询的时间 ret:秒数分量

fun time_unix_nsec

pub fun time_unix_nsec(t: Time) i64;

返回自 Unix 纪元以来的纳秒数

t:要查询的时间 ret:自纪元以来的总纳秒数

fun time_unix_usec

pub fun time_unix_usec(t: Time) i64;

返回自 Unix 纪元以来的微秒数

t:要查询的时间 ret:自纪元以来的总微秒数

fun time_unix_msec

pub fun time_unix_msec(t: Time) i64;

返回自 Unix 纪元以来的毫秒数

t:要查询的时间 ret:自纪元以来的总毫秒数

fun time_add

pub fun time_add(t: Time, d: Duration) Time;

返回 t + d

t:基础时间 d:要添加的持续时间 ret:偏移了 d 的新 Time

fun time_sub

pub fun time_sub(t: Time, u: Time) Duration;

返回持续时间 t - u

t:被减数时间 u:减数时间 rettu 之间的持续时间

fun time_before

pub fun time_before(t: Time, u: Time) bool;

报告 t 是否在 u 之前

t:要测试的时间 u:要与之比较的时间 ret:如果 t < u 则为 true

fun time_after

pub fun time_after(t: Time, u: Time) bool;

报告 t 是否在 u 之后

t:要测试的时间 u:要与之比较的时间 ret:如果 t > u 则为 true

fun time_equal

pub fun time_equal(t: Time, u: Time) bool;

报告 tu 是否表示相同的瞬间

t:第一个时间 u:第二个时间 ret:如果 t == u 则为 true

fun time_is_zero

pub fun time_is_zero(t: Time) bool;

报告 t 是否表示零时间瞬间

t:要测试的时间 ret:如果 t 是零时间(Unix 纪元)则为 true