data Time
UTC instant, nanoseconds since the Unix epoch (§17.1).
Example:
use std.time { Time }
fn main() io {
let t = Time.ofUnixSeconds(86400)
print("{t.toIso()} {t.unixSeconds()}")
}Output
1970-01-02T00:00:00Z 86400
Examples#
Recipes for points in time: Unix time, offsets, ISO 8601.
Unix time and ISO#
Time is an absolute point; it is created from Unix seconds or by parsing ISO 8601, shifted by a duration (t + 36h), and subtracting two points gives a Duration.
fn main() io {
let t = Time.ofUnixSeconds(1_700_000_000) // a point in time from Unix seconds
print("{t.toIso()} {t.date().toIso()}")
let later = t + 36h
print("{later.toIso()} {(later - t).hours()} h")
print("{Time.ofUnixMillis(1500).unixMillis()} {t.unixSeconds()}")
match Time.parse("2023-11-14T22:13:20Z") {
Time x => print("{x.unixSeconds()}")
ParseError => print("bad timestamp")
}
}Output
2023-11-14T22:13:20Z 2023-11-14 2023-11-16T10:13:20Z 36 h 1500 1700000000 1700000000
@builtin("Time") pub(api) data TimeThread safety. an immutable value.
Since. 1.0.0-beta
Defined in: std/core/types.oxl:113