pub struct UnixTimestamp(/* private fields */);Expand description
A unix timestamp (full seconds elapsed since 1970-01-01 00:00 UTC).
Implementations§
Source§impl UnixTimestamp
impl UnixTimestamp
Sourcepub const fn from_secs(secs: u64) -> Self
pub const fn from_secs(secs: u64) -> Self
Creates a unix timestamp from the given number of seconds.
Sourcepub fn from_system(time: SystemTime) -> Self
pub fn from_system(time: SystemTime) -> Self
Creates a unix timestamp from the given system time.
Sourcepub fn from_datetime(date_time: DateTime<impl TimeZone>) -> Option<Self>
pub fn from_datetime(date_time: DateTime<impl TimeZone>) -> Option<Self>
Creates a unix timestamp from the given chrono DateTime.
Returns Some if this is a valid date time starting with 1970-01-01 00:00 UTC. If the date
lies before the UNIX epoch, this function returns None.
Sourcepub fn from_instant(instant: Instant) -> Self
pub fn from_instant(instant: Instant) -> Self
Converts the given Instant into a UNIX timestamp.
This is done by comparing the Instant with the current system time. Note that the system
time is subject to skew, so subsequent calls to from_instant may return different values.
Sourcepub fn as_nanos(self) -> u64
pub fn as_nanos(self) -> u64
Returns the number of nanoseconds since the UNIX epoch start. Precision limited to seconds.
Sourcepub fn as_datetime(self) -> Option<DateTime<Utc>>
pub fn as_datetime(self) -> Option<DateTime<Utc>>
Returns the timestamp as chrono datetime.
Trait Implementations§
Source§impl Add<Duration> for UnixTimestamp
Adds whole seconds of the given duration to the timestamp.
impl Add<Duration> for UnixTimestamp
Adds whole seconds of the given duration to the timestamp.
Source§impl Clone for UnixTimestamp
impl Clone for UnixTimestamp
Source§fn clone(&self) -> UnixTimestamp
fn clone(&self) -> UnixTimestamp
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for UnixTimestamp
impl Debug for UnixTimestamp
Source§impl<'de> Deserialize<'de> for UnixTimestamp
impl<'de> Deserialize<'de> for UnixTimestamp
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl Display for UnixTimestamp
impl Display for UnixTimestamp
Source§impl FromStr for UnixTimestamp
impl FromStr for UnixTimestamp
Source§impl Hash for UnixTimestamp
impl Hash for UnixTimestamp
Source§impl Ord for UnixTimestamp
impl Ord for UnixTimestamp
Source§fn cmp(&self, other: &UnixTimestamp) -> Ordering
fn cmp(&self, other: &UnixTimestamp) -> Ordering
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for UnixTimestamp
impl PartialEq for UnixTimestamp
Source§fn eq(&self, other: &UnixTimestamp) -> bool
fn eq(&self, other: &UnixTimestamp) -> bool
self and other values to be equal, and is used by ==.