pub struct Timestamp {
pub secs: i64,
pub nanos: u32,
}Expand description
An instant: seconds since the Unix epoch, plus a nanosecond fraction.
The seconds are signed, so a time before 1970 is an ordinary value rather than a special
case. The fraction is nanoseconds within the second and is normally below
NANOS_PER_SEC — a timestamp decoded from an image need not be,
because the field it came out of may be wider than the second it divides, and what is
reported is what the image holds.
The type is exhaustive: an instant is a second and a fraction, and there is no field it could grow.
Fields§
§secs: i64Seconds since the Unix epoch, negative before it.
nanos: u32Nanoseconds within the second, normally 0..1_000_000_000.
Implementations§
Source§impl Timestamp
impl Timestamp
Sourcepub const NANOS_PER_SEC: u32 = 1_000_000_000
pub const NANOS_PER_SEC: u32 = 1_000_000_000
One past the largest fraction that divides a second.
Sourcepub const fn from_secs(secs: i64) -> Self
pub const fn from_secs(secs: i64) -> Self
An instant at secs seconds past the epoch, with no sub-second part.
Sourcepub const fn civil(self) -> Civil
pub const fn civil(self) -> Civil
The civil date and time of day this instant reads as, UTC.
The fraction is not carried across: a civil reading is a calendar position, and what
divides its final second is still nanos.
let civil = Timestamp::from_secs(1_700_000_000).civil();
assert_eq!((civil.year, civil.month, civil.day), (2023, 11, 14));
assert_eq!((civil.hour, civil.minute, civil.second), (22, 13, 20));