Struct Time
struct Time { ... }
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 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: Self) -> (u8, u8, u8)Get the clock hour, minute, and second.
# use time; assert_eq!; assert_eq!;const fn as_hms_milli(self: 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: 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: Self) -> (u8, u8, u8, u32)Get the clock hour, minute, second, and nanosecond.
# use time; assert_eq!; assert_eq!;const fn hour(self: 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: 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: 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: 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: 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: 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: Self, other: Self) -> DurationDetermine the
Durationthat, if added toself, would result in the parameter.# use Time; # use NumericalDuration; # use time; assert_eq!; assert_eq!;const fn duration_since(self: Self, other: Self) -> DurationDetermine the
Durationthat, if added to the parameter, would result inself.# use Time; # use NumericalDuration; # use time; assert_eq!; assert_eq!;const fn replace_hour(self: 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: 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: 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: Self) -> SelfTruncate the time to the minute, setting the second and subsecond components to zero.
# use time; assert_eq!;const fn replace_second(self: 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: Self) -> SelfTruncate the time to the second, setting the subsecond component to zero.
# use time; assert_eq!;const fn replace_millisecond(self: Self, millisecond: u16) -> Result<Self, ComponentRange>Replace the milliseconds within the second.
# use time; assert_eq!; assert!;const fn truncate_to_millisecond(self: Self) -> SelfTruncate the time to the millisecond, setting the microsecond and nanosecond components to zero.
# use time; assert_eq!;const fn replace_microsecond(self: Self, microsecond: u32) -> Result<Self, ComponentRange>Replace the microseconds within the second.
# use time; assert_eq!; assert!;const fn truncate_to_microsecond(self: Self) -> SelfTruncate the time to the microsecond, setting the nanosecond component to zero.
# use time; assert_eq!;const fn replace_nanosecond(self: Self, nanosecond: u32) -> Result<Self, ComponentRange>Replace the nanoseconds within the second.
# use time; assert_eq!; assert!;
impl Add for Time
fn add(self: Self, duration: Duration) -> <Self as >::OutputAdd the sub-day time of the
Durationto theTime. Wraps on overflow.# use NumericalDuration; # use time; assert_eq!; assert_eq!;
impl Add for Time
fn add(self: Self, duration: StdDuration) -> <Self as >::OutputAdd the sub-day time of the
std::time::Durationto theTime. Wraps on overflow.# use NumericalStdDuration; # use time; assert_eq!; assert_eq!;
impl AddAssign for Time
fn add_assign(self: &mut Self, rhs: Duration)
impl AddAssign for Time
fn add_assign(self: &mut Self, rhs: StdDuration)
impl Clone for Time
fn clone(self: &Self) -> Time
impl Copy for Time
impl Debug for Time
fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result
impl Display for Time
fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result
impl Eq for Time
impl Freeze for Time
impl Hash for Time
fn hash<H>(self: &Self, state: &mut H) where H: Hasher
impl Ord for Time
fn cmp(self: &Self, other: &Self) -> Ordering
impl PartialEq for Time
fn eq(self: &Self, other: &Self) -> bool
impl PartialOrd for Time
fn partial_cmp(self: &Self, other: &Self) -> Option<Ordering>
impl RefUnwindSafe for Time
impl Send for Time
impl SmartDisplay for Time
fn metadata(self: &Self, _: FormatterOptions) -> Metadata<'_, Self>fn fmt_with_metadata(self: &Self, f: &mut Formatter<'_>, metadata: Metadata<'_, Self>) -> Result
impl Sub for Time
fn sub(self: Self, duration: StdDuration) -> <Self as >::OutputSubtract the sub-day time of the
std::time::Durationfrom theTime. Wraps on overflow.# use NumericalStdDuration; # use time; assert_eq!; assert_eq!;
impl Sub for Time
fn sub(self: Self, rhs: Self) -> <Self as >::OutputSubtract two
Times, returning theDurationbetween. This assumes bothTimes are in the same calendar day.# use NumericalDuration; # use time; assert_eq!; assert_eq!; assert_eq!; assert_eq!;
impl Sub for Time
fn sub(self: Self, duration: Duration) -> <Self as >::OutputSubtract the sub-day time of the
Durationfrom theTime. Wraps on overflow.# use NumericalDuration; # use time; assert_eq!; assert_eq!;
impl SubAssign for Time
fn sub_assign(self: &mut Self, rhs: Duration)
impl SubAssign for Time
fn sub_assign(self: &mut Self, rhs: StdDuration)
impl Sync for Time
impl Unpin for Time
impl UnsafeUnpin for Time
impl UnwindSafe for Time
impl<T> Any for Time
fn type_id(self: &Self) -> TypeId
impl<T> Borrow for Time
fn borrow(self: &Self) -> &T
impl<T> BorrowMut for Time
fn borrow_mut(self: &mut Self) -> &mut T
impl<T> CloneToUninit for Time
unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)
impl<T> From for Time
fn from(t: T) -> TReturns the argument unchanged.
impl<T> ToOwned for Time
fn to_owned(self: &Self) -> Tfn clone_into(self: &Self, target: &mut T)
impl<T> ToString for Time
fn to_string(self: &Self) -> String
impl<T, U> Into for Time
fn into(self: Self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom for Time
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto for Time
fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>