pub struct UnixSeconds(/* private fields */);fmt only.Expand description
A system time represented as the number of whole seconds since the Unix epoch.
Examples:
0is equal toThu, 1 Jan 1970 00:00:00 -0000951786000is equal toTue, 29 Feb 2000 01:00:00 -0000
§UTC and time zones
The seconds are always represented in the UTC time zone.
§Serialization and deserialization
UnixSeconds implements the Serialize and Deserialize traits from the serde_core crate.
The system time is serialized as whole seconds. Fractional seconds are rounded down.
The serialization support is available when serde feature is enabled.
§Leap seconds
This value represents the number of non-leap seconds since the Unix epoch.
§Examples
§Parsing and formatting
This example demonstrates how to parse Unix seconds and convert them to SystemTime.
use std::time::{Duration, SystemTime};
use tick::fmt::UnixSeconds;
let unix_seconds = "9999".parse::<UnixSeconds>()?;
assert_eq!(unix_seconds.to_string(), "9999");
let system_time: SystemTime = unix_seconds.into();
assert_eq!(
system_time,
SystemTime::UNIX_EPOCH + Duration::from_secs(9999)
);
Implementations§
Source§impl UnixSeconds
impl UnixSeconds
Sourcepub const MAX: Self
pub const MAX: Self
The largest value that be can represented by UnixSeconds.
This represents a Unix system time of 31 December 9999 23:59:59 UTC.
Sourcepub const UNIX_EPOCH: Self
pub const UNIX_EPOCH: Self
The Unix epoch represented as UnixSeconds.
This represents a Unix system time of 1 January 1970 00:00:00 UTC.
Sourcepub fn from_secs(seconds: u64) -> Result<Self, Error>
pub fn from_secs(seconds: u64) -> Result<Self, Error>
Creates a new UnixSeconds from the given number of seconds since the Unix epoch.
§Errors
Returns an error if the provided seconds are out of range.
use tick::fmt::UnixSeconds;
UnixSeconds::from_secs(u64::MAX).unwrap_err();§Examples
use std::time::{Duration, SystemTime};
use tick::fmt::UnixSeconds;
let unix_seconds = UnixSeconds::from_secs(10).unwrap();
let system_time: SystemTime = unix_seconds.into();
assert_eq!(
system_time,
SystemTime::UNIX_EPOCH + Duration::from_secs(10)
);Trait Implementations§
Source§impl Clone for UnixSeconds
impl Clone for UnixSeconds
Source§fn clone(&self) -> UnixSeconds
fn clone(&self) -> UnixSeconds
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for UnixSeconds
Source§impl Debug for UnixSeconds
impl Debug for UnixSeconds
Source§impl<'de> Deserialize<'de> for UnixSeconds
Available on crate features serde only.
impl<'de> Deserialize<'de> for UnixSeconds
serde only.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 UnixSeconds
impl Display for UnixSeconds
impl Eq for UnixSeconds
Source§impl From<Iso8601> for UnixSeconds
impl From<Iso8601> for UnixSeconds
Source§impl From<Rfc2822> for UnixSeconds
impl From<Rfc2822> for UnixSeconds
Source§impl From<UnixSeconds> for Iso8601
impl From<UnixSeconds> for Iso8601
Source§fn from(value: UnixSeconds) -> Self
fn from(value: UnixSeconds) -> Self
Source§impl From<UnixSeconds> for Rfc2822
impl From<UnixSeconds> for Rfc2822
Source§fn from(value: UnixSeconds) -> Self
fn from(value: UnixSeconds) -> Self
Source§impl From<UnixSeconds> for SystemTime
impl From<UnixSeconds> for SystemTime
Source§fn from(value: UnixSeconds) -> Self
fn from(value: UnixSeconds) -> Self
Source§impl FromStr for UnixSeconds
impl FromStr for UnixSeconds
Source§impl Hash for UnixSeconds
impl Hash for UnixSeconds
Source§impl Ord for UnixSeconds
impl Ord for UnixSeconds
Source§fn cmp(&self, other: &UnixSeconds) -> Ordering
fn cmp(&self, other: &UnixSeconds) -> 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 UnixSeconds
impl PartialEq for UnixSeconds
Source§fn eq(&self, other: &UnixSeconds) -> bool
fn eq(&self, other: &UnixSeconds) -> bool
self and other values to be equal, and is used by ==.Source§impl PartialOrd for UnixSeconds
impl PartialOrd for UnixSeconds
Source§impl Serialize for UnixSeconds
Available on crate features serde only.
impl Serialize for UnixSeconds
serde only.