Struct Time
#[repr(C)]
pub struct Time { /* private fields */ }
The clock time within a given date. Nanosecond precision.
All minutes are assumed to have exactly 60 seconds; no attempt is made to handle leap seconds (either positive or negative).
When comparing two Times, they are assumed to be in the same calendar date.
Implementations
impl Time
const MIDNIGHT: Self = _;A
Timethat is exactly midnight. This is the smallest possible value for aTime.# use Time; # use time; assert_eq!;const MAX: Self = _;A
Timethat is one nanosecond before midnight. This is the largest possible value for aTime.# use Time; # use time; assert_eq!;const fn from_hms(hour: u8, minute: u8, second: u8) -> Result<Self, ComponentRange>Attempt to create a
Timefrom the hour, minute, and second.# use Time; assert!;# use Time; assert!; // 24 isn't a valid hour. assert!; // 60 isn't a valid minute. assert!; // 60 isn't a valid second.const fn from_hms_milli(hour: u8, minute: u8, second: u8, millisecond: u16) -> Result<Self, ComponentRange>Attempt to create a
Timefrom the hour, minute, second, and millisecond.# use Time; assert!;# use Time; assert!; // 24 isn't a valid hour. assert!; // 60 isn't a valid minute. assert!; // 60 isn't a valid second. assert!; // 1_000 isn't a valid millisecond.const fn from_hms_micro(hour: u8, minute: u8, second: u8, microsecond: u32) -> Result<Self, ComponentRange>Attempt to create a
Timefrom the hour, minute, second, and microsecond.# use Time; assert!;# use Time; assert!; // 24 isn't a valid hour. assert!; // 60 isn't a valid minute. assert!; // 60 isn't a valid second. assert!; // 1_000_000 isn't a valid microsecond.const fn from_hms_nano(hour: u8, minute: u8, second: u8, nanosecond: u32) -> Result<Self, ComponentRange>Attempt to create a
Timefrom the hour, minute, second, and nanosecond.# use Time; assert!;# use Time; assert!; // 24 isn't a valid hour. assert!; // 60 isn't a valid minute. assert!; // 60 isn't a valid second. assert!; // 1_000_000_000 isn't a valid nanosecond.const fn as_hms(self) -> (u8, u8, u8)Get the clock hour, minute, and second.
# use time; assert_eq!; assert_eq!;const fn as_hms_milli(self) -> (u8, u8, u8, u16)Get the clock hour, minute, second, and millisecond.
# use time; assert_eq!; assert_eq!;const fn as_hms_micro(self) -> (u8, u8, u8, u32)Get the clock hour, minute, second, and microsecond.
# use time; assert_eq!; assert_eq!;const fn as_hms_nano(self) -> (u8, u8, u8, u32)Get the clock hour, minute, second, and nanosecond.
# use time; assert_eq!; assert_eq!;const fn hour(self) -> u8Get the clock hour.
The returned value will always be in the range
0..24.# use time; assert_eq!; assert_eq!;const fn minute(self) -> u8Get the minute within the hour.
The returned value will always be in the range
0..60.# use time; assert_eq!; assert_eq!;const fn second(self) -> u8Get the second within the minute.
The returned value will always be in the range
0..60.# use time; assert_eq!; assert_eq!;const fn millisecond(self) -> u16Get the milliseconds within the second.
The returned value will always be in the range
0..1_000.# use time; assert_eq!; assert_eq!;const fn microsecond(self) -> u32Get the microseconds within the second.
The returned value will always be in the range
0..1_000_000.# use time; assert_eq!; assert_eq!;const fn nanosecond(self) -> u32Get the nanoseconds within the second.
The returned value will always be in the range
0..1_000_000_000.# use time; assert_eq!; assert_eq!;const fn duration_until(self, other: Self) -> SignedDurationDetermine the
SignedDurationthat, if added toself, would result in the parameter.# use Time; # use NumericalDuration; # use time; assert_eq!; assert_eq!;const fn duration_since(self, other: Self) -> SignedDurationDetermine the
SignedDurationthat, if added to the parameter, would result inself.# use Time; # use NumericalDuration; # use time; assert_eq!; assert_eq!;const fn replace_hour(self, hour: u8) -> Result<Self, ComponentRange>Replace the clock hour.
# use time; assert_eq!; assert!; // 24 isn't a valid hourconst fn truncate_to_hour(self) -> SelfTruncate the time to the hour, setting the minute, second, and subsecond components to zero.
# use time; assert_eq!;const fn replace_minute(self, minute: u8) -> Result<Self, ComponentRange>Replace the minutes within the hour.
# use time; assert_eq!; assert!; // 60 isn't a valid minuteconst fn truncate_to_minute(self) -> SelfTruncate the time to the minute, setting the second and subsecond components to zero.
# use time; assert_eq!;const fn replace_second(self, second: u8) -> Result<Self, ComponentRange>Replace the seconds within the minute.
# use time; assert_eq!; assert!; // 60 isn't a valid secondconst fn truncate_to_second(self) -> SelfTruncate the time to the second, setting the subsecond component to zero.
# use time; assert_eq!;const fn replace_millisecond(self, millisecond: u16) -> Result<Self, ComponentRange>Replace the milliseconds within the second.
# use time; assert_eq!; assert!;const fn truncate_to_millisecond(self) -> SelfTruncate the time to the millisecond, setting the microsecond and nanosecond components to zero.
# use time; assert_eq!;const fn replace_microsecond(self, microsecond: u32) -> Result<Self, ComponentRange>Replace the microseconds within the second.
# use time; assert_eq!; assert!;const fn truncate_to_microsecond(self) -> SelfTruncate the time to the microsecond, setting the nanosecond component to zero.
# use time; assert_eq!;const fn replace_nanosecond(self, nanosecond: u32) -> Result<Self, ComponentRange>Replace the nanoseconds within the second.
# use time; assert_eq!; assert!;
Trait Implementations
impl Add<Duration> for Time
type Output = Time;fn add(self, duration: StdDuration) -> Self::OutputAdd the sub-day time of the
std::time::Durationto theTime. Wraps on overflow.# use NumericalStdDuration; # use time; assert_eq!; assert_eq!;
impl Add<SignedDuration> for Time
type Output = Time;fn add(self, duration: SignedDuration) -> Self::OutputAdd the sub-day time of the
SignedDurationto theTime. Wraps on overflow.# use NumericalDuration; # use time; assert_eq!; assert_eq!;
impl AddAssign<Duration> for Time
fn add_assign(&mut self, rhs: StdDuration)
impl AddAssign<SignedDuration> for Time
fn add_assign(&mut self, rhs: SignedDuration)
impl Clone for Time
fn clone(&self) -> Self
impl Copy for Time
impl Debug for Time
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl Display for Time
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl Eq for Time
impl Hash for Time
fn hash<H>(&self, state: &mut H) where H: Hasher,
impl Ord for Time
fn cmp(&self, other: &Self) -> Ordering
impl PartialEq for Time
fn eq(&self, other: &Self) -> bool
impl PartialOrd for Time
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
impl SmartDisplay for Time
type Metadata = ();fn metadata(&self, FormatterOptions) -> Metadata<'_, Self>fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl Sub for Time
type Output = SignedDuration;fn sub(self, rhs: Self) -> Self::OutputSubtract two
Times, returning theSignedDurationbetween. This assumes bothTimes are in the same calendar day.# use NumericalDuration; # use time; assert_eq!; assert_eq!; assert_eq!; assert_eq!;
impl Sub<Duration> for Time
type Output = Time;fn sub(self, duration: StdDuration) -> Self::OutputSubtract the sub-day time of the
std::time::Durationfrom theTime. Wraps on overflow.# use NumericalStdDuration; # use time; assert_eq!; assert_eq!;
impl Sub<SignedDuration> for Time
type Output = Time;fn sub(self, duration: SignedDuration) -> Self::OutputSubtract the sub-day time of the
SignedDurationfrom theTime. Wraps on overflow.# use NumericalDuration; # use time; assert_eq!; assert_eq!;
impl SubAssign<Duration> for Time
fn sub_assign(&mut self, rhs: StdDuration)
impl SubAssign<SignedDuration> for Time
fn sub_assign(&mut self, rhs: SignedDuration)
Auto Trait Implementations
impl Freeze for Time
impl RefUnwindSafe for Time
impl Send for Time
impl Sync for Time
impl Unpin for Time
impl UnsafeUnpin for Time
impl UnwindSafe for Time
Blanket Implementations
impl<T> Any for Time
where
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
impl<T> Borrow<T> for Time
where
T: ?Sized,
fn borrow(&self) -> &T
impl<T> BorrowMut<T> for Time
where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
impl<T> CloneToUninit for Time
where
T: Clone,
unsafe fn clone_to_uninit(&self, dest: *mut u8)
impl<T> From<T> for Time
fn from(t: T) -> TReturns the argument unchanged.
impl<T> ToOwned for Time
where
T: Clone,
type Owned = T;fn to_owned(&self) -> Tfn clone_into(&self, target: &mut T)
impl<T> ToString for Time
where
T: Display + ?Sized,
fn to_string(&self) -> String
impl<T, U> Into<U> for Time
where
U: From<T>,
fn into(self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom<U> for Time
where
U: Into<T>,
type Error = never;fn try_from(value: U) -> Result<T, never>
impl<T, U> TryInto<U> for Time
where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error;fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>