Struct std::time::SystemTime [] [src]

pub struct SystemTime(_);
Unstable (time2 #29866)

: recently added

A measurement of the system clock appropriate for timestamps such as those on files on the filesystem.

Distinct from the Instant type, this time measurement is not monotonic. This means that you can save a file to the file system, then save another file to the file system, and the second file has a SystemTime measurement earlier than the second. In other words, an operation that happens after another operation in real time may have an earlier SystemTime!

Consequently, comparing two SystemTime instances to learn about the duration between them returns a Result instead of an infallible Duration to indicate that this sort of time drift may happen and needs to be handled.

Although a SystemTime cannot be directly inspected, the UNIX_EPOCH constant is provided in this module as an anchor in time to learn information about a SystemTime. By calculating the duration from this fixed point in time, a SystemTime can be converted to a human-readable time, or perhaps some other string representation.

Methods

impl SystemTime

fn now() -> SystemTime

Unstable (time2 #29866)

: recently added

Returns the system time corresponding to "now".

fn duration_from_earlier(&self, earlier: SystemTime) -> Result<Duration, SystemTimeError>

Unstable (time2 #29866)

: recently added

Returns the amount of time elapsed from an earlier point in time.

This function may fail because measurements taken earlier are not guaranteed to always be before later measurements (due to anomalies such as the system clock being adjusted either forwards or backwards).

If successful, Ok(Duration) is returned where the duration represents the amount of time elapsed from the specified measurement to this one.

Returns an Err if earlier is later than self, and the error contains how far from self the time is.

fn elapsed(&self) -> Result<Duration, SystemTimeError>

Unstable (time2 #29866)

: recently added

Returns the amount of time elapsed since this system time was created.

This function may fail as the underlying system clock is susceptible to drift and updates (e.g. the system clock could go backwards), so this function may not always succeed. If successful, Ok(duration) is returned where the duration represents the amount of time elapsed from this time measurement to the current time.

Returns an Err if self is later than the current system time, and the error contains how far from the current system time self is.

Trait Implementations

impl Add<Duration> for SystemTime

type Output = SystemTime

fn add(self, dur: Duration) -> SystemTime

impl Sub<Duration> for SystemTime

type Output = SystemTime

fn sub(self, dur: Duration) -> SystemTime

impl Debug for SystemTime

fn fmt(&self, f: &mut Formatter) -> Result

Derived Implementations

impl Ord for SystemTime

fn cmp(&self, __arg_0: &SystemTime) -> Ordering

impl PartialOrd for SystemTime

fn partial_cmp(&self, __arg_0: &SystemTime) -> Option<Ordering>

fn lt(&self, __arg_0: &SystemTime) -> bool

fn le(&self, __arg_0: &SystemTime) -> bool

fn gt(&self, __arg_0: &SystemTime) -> bool

fn ge(&self, __arg_0: &SystemTime) -> bool

impl Eq for SystemTime

impl PartialEq for SystemTime

fn eq(&self, __arg_0: &SystemTime) -> bool

fn ne(&self, __arg_0: &SystemTime) -> bool

impl Clone for SystemTime

fn clone(&self) -> SystemTime

fn clone_from(&mut self, source: &Self)

impl Copy for SystemTime