pub struct Timestamp(/* private fields */);Expand description
An instant in time represented as the number of nanoseconds since the Unix epoch.
Implementations§
Source§impl Timestamp
impl Timestamp
Sourcepub fn format_date(self) -> String
pub fn format_date(self) -> String
Format the timestamp into date: 20220301
Sourcepub fn format_iso8601(self) -> String
pub fn format_iso8601(self) -> String
Format the timestamp into ISO8601: 20220313T072004Z
Sourcepub fn format_http_date(self) -> String
pub fn format_http_date(self) -> String
Format the timestamp into http date: Sun, 06 Nov 1994 08:49:37 GMT
§Note
HTTP date is slightly different from RFC2822.
- Timezone is fixed to GMT.
- Day must be 2 digit.
Sourcepub fn format_rfc3339_zulu(self) -> String
pub fn format_rfc3339_zulu(self) -> String
Format the timestamp into RFC3339 in Zulu: 2022-03-13T07:20:04Z
Sourcepub fn as_second(self) -> i64
pub fn as_second(self) -> i64
Returns this timestamp as a number of seconds since the Unix epoch.
This only returns the number of whole seconds. That is, if there are any fractional seconds in this timestamp, then they are truncated.
Sourcepub fn subsec_nanosecond(self) -> i32
pub fn subsec_nanosecond(self) -> i32
Returns the fractional second component of this timestamp in units of nanoseconds.
It is guaranteed that this will never return a value that is greater than 1 second (or less than -1 second).
Sourcepub fn as_system_time(self) -> SystemTime
pub fn as_system_time(self) -> SystemTime
Convert to SystemTime.
Sourcepub fn from_millisecond(millis: i64) -> Result<Self>
pub fn from_millisecond(millis: i64) -> Result<Self>
Creates a new instant in time from the number of milliseconds elapsed since the Unix epoch.
When millisecond is negative, it corresponds to an instant in time
before the Unix epoch. A smaller number corresponds to an instant in
time further into the past.
Sourcepub fn from_second(second: i64) -> Result<Self>
pub fn from_second(second: i64) -> Result<Self>
Creates a new instant in time from the number of seconds elapsed since the Unix epoch.
When second is negative, it corresponds to an instant in time before
the Unix epoch. A smaller number corresponds to an instant in time
further into the past.
Sourcepub fn parse_rfc2822(s: &str) -> Result<Timestamp>
pub fn parse_rfc2822(s: &str) -> Result<Timestamp>
Parse a timestamp from RFC2822.
All of them are valid time:
Sat, 13 Jul 2024 15:09:59 -0400Mon, 15 Aug 2022 16:50:12 GMT
Sourcepub fn parse_datetime_utc(s: &str) -> Result<Timestamp>
pub fn parse_datetime_utc(s: &str) -> Result<Timestamp>
Parse the string format “2023-10-31 21:59:10.000000”.
Trait Implementations§
Source§impl AddAssign<Duration> for Timestamp
impl AddAssign<Duration> for Timestamp
Source§fn add_assign(&mut self, rhs: Duration)
fn add_assign(&mut self, rhs: Duration)
+= operation. Read moreSource§impl FromStr for Timestamp
impl FromStr for Timestamp
Source§impl Ord for Timestamp
impl Ord for Timestamp
Source§impl PartialOrd for Timestamp
impl PartialOrd for Timestamp
Source§impl SubAssign<Duration> for Timestamp
impl SubAssign<Duration> for Timestamp
Source§fn sub_assign(&mut self, rhs: Duration)
fn sub_assign(&mut self, rhs: Duration)
-= operation. Read more