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_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
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
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
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>,
Deserialize this value from the given Serde deserializer. Read more
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 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
source§impl PartialEq for UnixTimestamp
impl PartialEq for UnixTimestamp
source§impl PartialOrd for UnixTimestamp
impl PartialOrd for UnixTimestamp
source§impl Serialize for UnixTimestamp
impl Serialize for UnixTimestamp
source§impl Sub for UnixTimestamp
impl Sub for UnixTimestamp
impl Copy for UnixTimestamp
impl Eq for UnixTimestamp
impl StructuralPartialEq for UnixTimestamp
Auto Trait Implementations§
impl Freeze for UnixTimestamp
impl RefUnwindSafe for UnixTimestamp
impl Send for UnixTimestamp
impl Sync for UnixTimestamp
impl Unpin for UnixTimestamp
impl UnwindSafe for UnixTimestamp
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)