Time

Struct Time 

Source
pub struct Time { /* private fields */ }
Expand description

A Time represents an instant in time with nanosecond precision.

Implementations§

Source§

impl Time

Source

pub fn from_systime(sys_time: &SystemTime) -> Self

from_systime creates Time structure from std::time::SystemTime

Examples found in repository?
examples/time.rs (line 13)
8fn main() {
9    println!("epoch start: {}", format_time(&time::unix(0, 0)));
10    println!("now:         {}", format_time(&time::now()));
11    println!(
12        "now systime: {}",
13        format_time(&Time::from_systime(&SystemTime::now()))
14    );
15}
Source

pub fn from_unix(sec: i64, nsec: i64) -> Self

unix returns the local Time corresponding to the given Unix time, sec seconds and nsec nanoseconds since January 1, 1970 UTC. It is valid to pass nsec outside the range [0, 999999999]. Not all sec values have a corresponding time value. One such value is 1<<63-1 (the largest i64 value).

This is the same as unix.

Source§

impl Time

Source

pub fn date(&self) -> YMD

Source

pub fn year(&self) -> isize

year returns the year in which t occurs.

Examples found in repository?
examples/time.rs (line 20)
17fn format_time(t: &Time) -> String {
18    format!(
19        "{:04}-{:02}-{:02} {:02}:{:02}:{:02}",
20        t.year(),
21        t.month(),
22        t.day(),
23        t.hour(),
24        t.minute(),
25        t.second()
26    )
27}
Source

pub fn month(&self) -> usize

month returns the month of the year specified by self.

Examples found in repository?
examples/time.rs (line 21)
17fn format_time(t: &Time) -> String {
18    format!(
19        "{:04}-{:02}-{:02} {:02}:{:02}:{:02}",
20        t.year(),
21        t.month(),
22        t.day(),
23        t.hour(),
24        t.minute(),
25        t.second()
26    )
27}
Source

pub fn day(&self) -> usize

Examples found in repository?
examples/time.rs (line 22)
17fn format_time(t: &Time) -> String {
18    format!(
19        "{:04}-{:02}-{:02} {:02}:{:02}:{:02}",
20        t.year(),
21        t.month(),
22        t.day(),
23        t.hour(),
24        t.minute(),
25        t.second()
26    )
27}
Source

pub fn weekday(&self) -> usize

Source§

impl Time

Source

pub fn clock(&self) -> HMS

clock returns the hour, minute, and second within the day specified by self.

Source

pub fn hour(&self) -> u8

hour returns the hour within the day specified by t, in the range [0, 23].

Examples found in repository?
examples/time.rs (line 23)
17fn format_time(t: &Time) -> String {
18    format!(
19        "{:04}-{:02}-{:02} {:02}:{:02}:{:02}",
20        t.year(),
21        t.month(),
22        t.day(),
23        t.hour(),
24        t.minute(),
25        t.second()
26    )
27}
Source

pub fn minute(&self) -> u8

minute returns the minute offset within the hour specified by t, in the range [0, 59].

Examples found in repository?
examples/time.rs (line 24)
17fn format_time(t: &Time) -> String {
18    format!(
19        "{:04}-{:02}-{:02} {:02}:{:02}:{:02}",
20        t.year(),
21        t.month(),
22        t.day(),
23        t.hour(),
24        t.minute(),
25        t.second()
26    )
27}
Source

pub fn second(&self) -> u8

second returns the second offset within the minute specified by t, in the range [0, 59].

Examples found in repository?
examples/time.rs (line 25)
17fn format_time(t: &Time) -> String {
18    format!(
19        "{:04}-{:02}-{:02} {:02}:{:02}:{:02}",
20        t.year(),
21        t.month(),
22        t.day(),
23        t.hour(),
24        t.minute(),
25        t.second()
26    )
27}
Source

pub fn nanosecond(&self) -> usize

nanosecond returns the nanosecond offset within the second specified by t, in the range [0, 999999999].

Source

pub fn year_day(&self) -> usize

year_day returns the day of the year specified by t, in the range [1,365] for non-leap years, and [1,366] in leap years.

Source§

impl Time

Source

pub fn unix(&self) -> i64

Source

pub fn unix_nano(&self) -> i64

unix_nano returns t as a Unix time, the number of nanoseconds elapsed since January 1, 1970 UTC. The result is undefined if the Unix time in nanoseconds cannot be represented by an i64 (a date before the year 1678 or after 2262). Note that this means the result of calling unix_nano on the zero Time is undefined. The result does not depend on the location associated with t.

Trait Implementations§

Source§

impl Debug for Time

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for Time

Source§

fn default() -> Time

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Time

§

impl RefUnwindSafe for Time

§

impl Send for Time

§

impl Sync for Time

§

impl Unpin for Time

§

impl UnwindSafe for Time

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.