Struct time::Tm

source ·
#[repr(C)]
pub struct Tm { pub tm_sec: i32, pub tm_min: i32, pub tm_hour: i32, pub tm_mday: i32, pub tm_mon: i32, pub tm_year: i32, pub tm_wday: i32, pub tm_yday: i32, pub tm_isdst: i32, pub tm_utcoff: i32, pub tm_nsec: i32, }
Expand description

Holds a calendar date and time broken down into its components (year, month, day, and so on), also called a broken-down time value.

Fields§

§tm_sec: i32

Seconds after the minute - [0, 60]

§tm_min: i32

Minutes after the hour - [0, 59]

§tm_hour: i32

Hours after midnight - [0, 23]

§tm_mday: i32

Day of the month - [1, 31]

§tm_mon: i32

Months since January - [0, 11]

§tm_year: i32

Years since 1900

§tm_wday: i32

Days since Sunday - [0, 6]. 0 = Sunday, 1 = Monday, …, 6 = Saturday.

§tm_yday: i32

Days since January 1 - [0, 365]

§tm_isdst: i32

Daylight Saving Time flag.

This value is positive if Daylight Saving Time is in effect, zero if Daylight Saving Time is not in effect, and negative if this information is not available.

§tm_utcoff: i32

Identifies the time zone that was used to compute this broken-down time value, including any adjustment for Daylight Saving Time. This is the number of seconds east of UTC. For example, for U.S. Pacific Daylight Time, the value is -7*60*60 = -25200.

§tm_nsec: i32

Nanoseconds after the second - [0, 109 - 1]

Implementations§

source§

impl Tm

source

pub fn to_timespec(&self) -> Timespec

Convert time to the seconds from January 1, 1970

source

pub fn to_local(&self) -> Tm

Convert time to the local timezone

source

pub fn to_utc(&self) -> Tm

Convert time to the UTC

source

pub fn ctime(&self) -> TmFmt<'_>

Returns a TmFmt that outputs according to the asctime format in ISO C, in the local timezone.

Example: “Thu Jan 1 00:00:00 1970”

source

pub fn asctime(&self) -> TmFmt<'_>

Returns a TmFmt that outputs according to the asctime format in ISO C.

Example: “Thu Jan 1 00:00:00 1970”

source

pub fn strftime<'a>(&'a self, format: &'a str) -> Result<TmFmt<'a>, ParseError>

Formats the time according to the format string.

source

pub fn rfc822(&self) -> TmFmt<'_>

Returns a TmFmt that outputs according to RFC 822.

local: “Thu, 22 Mar 2012 07:53:18 PST” utc: “Thu, 22 Mar 2012 14:53:18 GMT”

source

pub fn rfc822z(&self) -> TmFmt<'_>

Returns a TmFmt that outputs according to RFC 822 with Zulu time.

local: “Thu, 22 Mar 2012 07:53:18 -0700” utc: “Thu, 22 Mar 2012 14:53:18 -0000”

source

pub fn rfc3339<'a>(&'a self) -> TmFmt<'_>

Returns a TmFmt that outputs according to RFC 3339. RFC 3339 is compatible with ISO 8601.

local: “2012-02-22T07:53:18-07:00” utc: “2012-02-22T14:53:18Z”

Trait Implementations§

source§

impl Add<Duration> for Tm

source§

fn add(self, other: Duration) -> Tm

The resulting Tm is in UTC.

§

type Output = Tm

The resulting type after applying the + operator.
source§

impl Clone for Tm

source§

fn clone(&self) -> Tm

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl Debug for Tm

source§

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

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

impl Hash for Tm

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl Ord for Tm

source§

fn cmp(&self, other: &Tm) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq for Tm

source§

fn eq(&self, other: &Tm) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for Tm

source§

fn partial_cmp(&self, other: &Tm) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Sub<Duration> for Tm

source§

fn sub(self, other: Duration) -> Tm

The resulting Tm is in UTC.

§

type Output = Tm

The resulting type after applying the - operator.
source§

impl Sub for Tm

§

type Output = Duration

The resulting type after applying the - operator.
source§

fn sub(self, other: Tm) -> Duration

Performs the - operation. Read more
source§

impl Copy for Tm

source§

impl Eq for Tm

source§

impl StructuralPartialEq for Tm

Auto Trait Implementations§

§

impl Freeze for Tm

§

impl RefUnwindSafe for Tm

§

impl Send for Tm

§

impl Sync for Tm

§

impl Unpin for Tm

§

impl UnwindSafe for Tm

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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

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>,

§

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.