pub struct TimestampMs(/* private fields */);Expand description
A timestamp in milliseconds since the UNIX epoch (January 1, 1970). Serialized as a non-negative integer.
Implementations§
Source§impl TimestampMs
impl TimestampMs
pub const MIN: Self
pub const MAX: Self
Sourcepub fn now() -> Self
pub fn now() -> Self
Creates a new TimestampMs from the current SystemTime.
Panics if the current time is not within bounds.
Sourcepub fn from_secs(secs: u64) -> Result<Self, Error>
pub fn from_secs(secs: u64) -> Result<Self, Error>
Construct TimestampMs from seconds since Unix epoch.
Sourcepub fn from_secs_u32(secs: u32) -> Self
pub fn from_secs_u32(secs: u32) -> Self
Infallibly construct TimestampMs from seconds since Unix epoch.
Sourcepub fn from_millis(millis: u64) -> Result<Self, Error>
pub fn from_millis(millis: u64) -> Result<Self, Error>
Construct TimestampMs from milliseconds since Unix epoch.
Sourcepub fn from_duration(dur_since_epoch: Duration) -> Result<Self, Error>
pub fn from_duration(dur_since_epoch: Duration) -> Result<Self, Error>
Construct TimestampMs from Duration since Unix epoch.
Sourcepub fn from_system_time(system_time: SystemTime) -> Result<Self, Error>
pub fn from_system_time(system_time: SystemTime) -> Result<Self, Error>
Construct TimestampMs from a SystemTime.
Sourcepub fn to_millis(self) -> u64
pub fn to_millis(self) -> u64
Get this unix timestamp as a u64 in milliseconds from unix epoch.
Sourcepub fn to_duration(self) -> Duration
pub fn to_duration(self) -> Duration
Get this unix timestamp as a Duration from the unix epoch.
Sourcepub fn to_system_time(self) -> SystemTime
pub fn to_system_time(self) -> SystemTime
Get this unix timestamp as a SystemTime.
pub fn checked_add(self, duration: Duration) -> Option<Self>
pub fn checked_sub(self, duration: Duration) -> Option<Self>
pub fn saturating_add(self, duration: Duration) -> Self
pub fn saturating_sub(self, duration: Duration) -> Self
Sourcepub fn absolute_diff(self, other: Self) -> Duration
pub fn absolute_diff(self, other: Self) -> Duration
Returns the absolute difference two timestamps as a Duration.
Trait Implementations§
Source§impl Clone for TimestampMs
impl Clone for TimestampMs
Source§fn clone(&self) -> TimestampMs
fn clone(&self) -> TimestampMs
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for TimestampMs
impl Debug for TimestampMs
Source§impl<'de> Deserialize<'de> for TimestampMs
impl<'de> Deserialize<'de> for TimestampMs
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 TimestampMs
impl Display for TimestampMs
Source§impl From<TimestampMs> for Duration
impl From<TimestampMs> for Duration
Source§fn from(t: TimestampMs) -> Self
fn from(t: TimestampMs) -> Self
Source§impl From<TimestampMs> for SystemTime
impl From<TimestampMs> for SystemTime
Source§fn from(t: TimestampMs) -> Self
fn from(t: TimestampMs) -> Self
Source§impl FromStr for TimestampMs
impl FromStr for TimestampMs
Source§impl Hash for TimestampMs
impl Hash for TimestampMs
Source§impl Ord for TimestampMs
impl Ord for TimestampMs
Source§fn cmp(&self, other: &TimestampMs) -> Ordering
fn cmp(&self, other: &TimestampMs) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for TimestampMs
impl PartialEq for TimestampMs
Source§impl PartialOrd for TimestampMs
impl PartialOrd for TimestampMs
Source§impl Serialize for TimestampMs
impl Serialize for TimestampMs
Source§impl TryFrom<Duration> for TimestampMs
Attempts to convert a Duration since the UNIX epoch into a
TimestampMs.
impl TryFrom<Duration> for TimestampMs
Attempts to convert a Duration since the UNIX epoch into a
TimestampMs.
Returns an error if the Duration is too large.
Source§impl TryFrom<SystemTime> for TimestampMs
Attempts to convert a SystemTime into a TimestampMs.
impl TryFrom<SystemTime> for TimestampMs
Attempts to convert a SystemTime into a TimestampMs.
Returns an error if the SystemTime is not within bounds.
Source§impl TryFrom<i64> for TimestampMs
Attempt to convert an i64 in milliseconds since unix epoch into a
TimestampMs.
impl TryFrom<i64> for TimestampMs
Attempt to convert an i64 in milliseconds since unix epoch into a
TimestampMs.