Struct NaiveDateTime
struct NaiveDateTime { ... }
ISO 8601 combined date and time without timezone.
Example
NaiveDateTime is commonly created from NaiveDate.
use ;
let dt: NaiveDateTime =
from_ymd_opt.unwrap.and_hms_opt.unwrap;
# let _ = dt;
You can use typical date-like and time-like methods, provided that relevant traits are in the scope.
# use ;
# let dt: NaiveDateTime = from_ymd_opt.unwrap.and_hms_opt.unwrap;
use ;
assert_eq!;
assert_eq!;
Implementations
impl NaiveDateTime
const fn new(date: NaiveDate, time: NaiveTime) -> NaiveDateTimeMakes a new
NaiveDateTimefrom date and time components. Equivalent todate.and_time(time)and many other helper constructors onNaiveDate.Example
use ; let d = from_ymd_opt.unwrap; let t = from_hms_milli_opt.unwrap; let dt = new; assert_eq!; assert_eq!;const fn from_timestamp(secs: i64, nsecs: u32) -> NaiveDateTimeMakes a new
NaiveDateTimecorresponding to a UTC date and time, from the number of non-leap seconds since the midnight UTC on January 1, 1970 (aka "UNIX timestamp") and the number of nanoseconds since the last whole non-leap second.For a non-naive version of this function see
TimeZone::timestamp.The nanosecond part can exceed 1,000,000,000 in order to represent a leap second, but only when
secs % 60 == 59. (The true "UNIX timestamp" cannot represent a leap second unambiguously.)Panics
Panics if the number of seconds would be out of range for a
NaiveDateTime(more than ca. 262,000 years away from common era), and panics on an invalid nanosecond (2 seconds or more).const fn from_timestamp_millis(millis: i64) -> Option<NaiveDateTime>Creates a new [NaiveDateTime] from milliseconds since the UNIX epoch.
The UNIX epoch starts on midnight, January 1, 1970, UTC.
Errors
Returns
Noneif the number of milliseconds would be out of range for aNaiveDateTime(more than ca. 262,000 years away from common era)const fn from_timestamp_micros(micros: i64) -> Option<NaiveDateTime>Creates a new [NaiveDateTime] from microseconds since the UNIX epoch.
The UNIX epoch starts on midnight, January 1, 1970, UTC.
Errors
Returns
Noneif the number of microseconds would be out of range for aNaiveDateTime(more than ca. 262,000 years away from common era)const fn from_timestamp_nanos(nanos: i64) -> Option<NaiveDateTime>Creates a new [NaiveDateTime] from nanoseconds since the UNIX epoch.
The UNIX epoch starts on midnight, January 1, 1970, UTC.
Errors
Returns
Noneif the number of nanoseconds would be out of range for aNaiveDateTime(more than ca. 262,000 years away from common era)const fn from_timestamp_opt(secs: i64, nsecs: u32) -> Option<NaiveDateTime>Makes a new
NaiveDateTimecorresponding to a UTC date and time, from the number of non-leap seconds since the midnight UTC on January 1, 1970 (aka "UNIX timestamp") and the number of nanoseconds since the last whole non-leap second.The nanosecond part can exceed 1,000,000,000 in order to represent a leap second, but only when
secs % 60 == 59. (The true "UNIX timestamp" cannot represent a leap second unambiguously.)Errors
Returns
Noneif the number of seconds would be out of range for aNaiveDateTime(more than ca. 262,000 years away from common era), and panics on an invalid nanosecond (2 seconds or more).fn parse_from_str(s: &str, fmt: &str) -> ParseResult<NaiveDateTime>Parses a string with the specified format string and returns a new
NaiveDateTime. See theformat::strftimemodule on the supported escape sequences.Example
use ; let parse_from_str = parse_from_str; assert_eq!; assert_eq!;Offset is ignored for the purpose of parsing.
# use ; # let parse_from_str = parse_from_str; assert_eq!;Leap seconds are correctly handled by treating any time of the form
hh:mm:60as a leap second. (This equally applies to the formatting, so the round trip is possible.)# use ; # let parse_from_str = parse_from_str; assert_eq!;Missing seconds are assumed to be zero, but out-of-bound times or insufficient fields are errors otherwise.
# use ; # let parse_from_str = parse_from_str; assert_eq!; assert!; assert!; assert!; assert!;All parsed fields should be consistent to each other, otherwise it's an error.
# use NaiveDateTime; # let parse_from_str = parse_from_str; let fmt = "%Y-%m-%d %H:%M:%S = UNIX timestamp %s"; assert!; assert!;Years before 1 BCE or after 9999 CE, require an initial sign
# use NaiveDateTime; # let parse_from_str = parse_from_str; let fmt = "%Y-%m-%d %H:%M:%S"; assert!; assert!;fn parse_and_remainder<'a>(s: &'a str, fmt: &str) -> ParseResult<(NaiveDateTime, &'a str)>Parses a string with the specified format string and returns a new
NaiveDateTime, and a slice with the remaining portion of the string. See theformat::strftimemodule on the supported escape sequences.Similar to
parse_from_str.Example
# use ; let = parse_and_remainder .unwrap; assert_eq!; assert_eq!;const fn date(self: &Self) -> NaiveDateRetrieves a date component.
Example
use NaiveDate; let dt = from_ymd_opt.unwrap.and_hms_opt.unwrap; assert_eq!;const fn time(self: &Self) -> NaiveTimeRetrieves a time component.
Example
use ; let dt = from_ymd_opt.unwrap.and_hms_opt.unwrap; assert_eq!;const fn timestamp(self: &Self) -> i64Returns the number of non-leap seconds since the midnight on January 1, 1970.
Note that this does not account for the timezone! The true "UNIX timestamp" would count seconds since the midnight UTC on the epoch.
const fn timestamp_millis(self: &Self) -> i64Returns the number of non-leap milliseconds since midnight on January 1, 1970.
Note that this does not account for the timezone! The true "UNIX timestamp" would count seconds since the midnight UTC on the epoch.
const fn timestamp_micros(self: &Self) -> i64Returns the number of non-leap microseconds since midnight on January 1, 1970.
Note that this does not account for the timezone! The true "UNIX timestamp" would count seconds since the midnight UTC on the epoch.
const fn timestamp_nanos(self: &Self) -> i64Returns the number of non-leap nanoseconds since midnight on January 1, 1970.
Note that this does not account for the timezone! The true "UNIX timestamp" would count seconds since the midnight UTC on the epoch.
Panics
An
i64with nanosecond precision can span a range of ~584 years. This function panics on an out of rangeNaiveDateTime.The dates that can be represented as nanoseconds are between 1677-09-21T00:12:43.145224192 and 2262-04-11T23:47:16.854775807.
const fn timestamp_nanos_opt(self: &Self) -> Option<i64>Returns the number of non-leap nanoseconds since midnight on January 1, 1970.
Note that this does not account for the timezone! The true "UNIX timestamp" would count seconds since the midnight UTC on the epoch.
Errors
An
i64with nanosecond precision can span a range of ~584 years. This function returnsNoneon an out of rangeNaiveDateTime.The dates that can be represented as nanoseconds are between 1677-09-21T00:12:43.145224192 and 2262-04-11T23:47:16.854775807.
const fn timestamp_subsec_millis(self: &Self) -> u32Returns the number of milliseconds since the last whole non-leap second.
The return value ranges from 0 to 999, or for leap seconds, to 1,999.
const fn timestamp_subsec_micros(self: &Self) -> u32Returns the number of microseconds since the last whole non-leap second.
The return value ranges from 0 to 999,999, or for leap seconds, to 1,999,999.
const fn timestamp_subsec_nanos(self: &Self) -> u32Returns the number of nanoseconds since the last whole non-leap second.
The return value ranges from 0 to 999,999,999, or for leap seconds, to 1,999,999,999.
const fn checked_add_signed(self: Self, rhs: TimeDelta) -> Option<NaiveDateTime>Adds given
TimeDeltato the current date and time.As a part of Chrono's leap second handling, the addition assumes that there is no leap second ever, except when the
NaiveDateTimeitself represents a leap second in which case the assumption becomes that there is exactly a single leap second ever.Errors
Returns
Noneif the resulting date would be out of range.Example
use ; let from_ymd = ; let d = from_ymd; let hms = ; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!; let hmsm = ; assert_eq!;Overflow returns
None.# use ; # let hms = ; assert_eq!;Leap seconds are handled, but the addition assumes that it is the only leap second happened.
# use ; # let from_ymd = ; # let hmsm = ; let leap = hmsm; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!;const fn checked_add_months(self: Self, rhs: Months) -> Option<NaiveDateTime>Adds given
Monthsto the current date and time.Uses the last day of the month if the day does not exist in the resulting month.
Errors
Returns
Noneif the resulting date would be out of range.Example
use ; assert_eq!; assert_eq!;const fn checked_add_offset(self: Self, rhs: FixedOffset) -> Option<NaiveDateTime>Adds given
FixedOffsetto the current datetime. ReturnsNoneif the result would be outside the valid range forNaiveDateTime.This method is similar to
checked_add_signed, but preserves leap seconds.const fn checked_sub_offset(self: Self, rhs: FixedOffset) -> Option<NaiveDateTime>Subtracts given
FixedOffsetfrom the current datetime. ReturnsNoneif the result would be outside the valid range forNaiveDateTime.This method is similar to
checked_sub_signed, but preserves leap seconds.const fn checked_sub_signed(self: Self, rhs: TimeDelta) -> Option<NaiveDateTime>Subtracts given
TimeDeltafrom the current date and time.As a part of Chrono's leap second handling, the subtraction assumes that there is no leap second ever, except when the
NaiveDateTimeitself represents a leap second in which case the assumption becomes that there is exactly a single leap second ever.Errors
Returns
Noneif the resulting date would be out of range.Example
use ; let from_ymd = ; let d = from_ymd; let hms = ; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!; let hmsm = ; assert_eq!;Overflow returns
None.# use ; # let hms = ; assert_eq!;Leap seconds are handled, but the subtraction assumes that it is the only leap second happened.
# use ; # let from_ymd = ; # let hmsm = ; let leap = hmsm; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!;const fn checked_sub_months(self: Self, rhs: Months) -> Option<NaiveDateTime>Subtracts given
Monthsfrom the current date and time.Uses the last day of the month if the day does not exist in the resulting month.
Errors
Returns
Noneif the resulting date would be out of range.Example
use ; assert_eq!; assert_eq!;const fn checked_add_days(self: Self, days: Days) -> Option<Self>Add a duration in
Daysto the date part of theNaiveDateTimeReturns
Noneif the resulting date would be out of range.const fn checked_sub_days(self: Self, days: Days) -> Option<Self>Subtract a duration in
Daysfrom the date part of theNaiveDateTimeReturns
Noneif the resulting date would be out of range.const fn signed_duration_since(self: Self, rhs: NaiveDateTime) -> TimeDeltaSubtracts another
NaiveDateTimefrom the current date and time. This does not overflow or underflow at all.As a part of Chrono's leap second handling, the subtraction assumes that there is no leap second ever, except when any of the
NaiveDateTimes themselves represents a leap second in which case the assumption becomes that there are exactly one (or two) leap second(s) ever.Example
use ; let from_ymd = ; let d = from_ymd; assert_eq!; // July 8 is 190th day in the year 2016 let d0 = from_ymd; assert_eq!;Leap seconds are handled, but the subtraction assumes that there were no other leap seconds happened.
# use ; # let from_ymd = ; let leap = from_ymd.and_hms_milli_opt.unwrap; assert_eq!; assert_eq!;fn format_with_items<'a, I, B>(self: &Self, items: I) -> DelayedFormat<I> where I: Iterator<Item = B> + Clone, B: Borrow<Item<'a>>Formats the combined date and time with the specified formatting items. Otherwise it is the same as the ordinary
formatmethod.The
Iteratorof items should beCloneable, since the resultingDelayedFormatvalue may be formatted multiple times.Example
use StrftimeItems; use NaiveDate; let fmt = new; let dt = from_ymd_opt.unwrap.and_hms_opt.unwrap; assert_eq!; assert_eq!;The resulting
DelayedFormatcan be formatted directly via theDisplaytrait.# use NaiveDate; # use StrftimeItems; # let fmt = new.clone; # let dt = from_ymd_opt.unwrap.and_hms_opt.unwrap; assert_eq!;fn format<'a>(self: &Self, fmt: &'a str) -> DelayedFormat<StrftimeItems<'a>>Formats the combined date and time with the specified format string. See the
format::strftimemodule on the supported escape sequences.This returns a
DelayedFormat, which gets converted to a string only when actual formatting happens. You may use theto_stringmethod to get aString, or just feed it intoprint!and other formatting macros. (In this way it avoids the redundant memory allocation.)A wrong format string does not issue an error immediately. Rather, converting or formatting the
DelayedFormatfails. You are recommended to immediately useDelayedFormatfor this reason.Example
use NaiveDate; let dt = from_ymd_opt.unwrap.and_hms_opt.unwrap; assert_eq!; assert_eq!;The resulting
DelayedFormatcan be formatted directly via theDisplaytrait.# use NaiveDate; # let dt = from_ymd_opt.unwrap.and_hms_opt.unwrap; assert_eq!; assert_eq!;fn and_local_timezone<Tz: TimeZone>(self: &Self, tz: Tz) -> MappedLocalTime<DateTime<Tz>>Converts the
NaiveDateTimeinto a timezone-awareDateTime<Tz>with the provided time zone.Example
use ; let hour = 3600; let tz = east_opt.unwrap; let dt = from_ymd_opt .unwrap .and_hms_opt .unwrap .and_local_timezone .unwrap; assert_eq!;const fn and_utc(self: &Self) -> DateTime<Utc>Converts the
NaiveDateTimeinto the timezone-awareDateTime<Utc>.Example
use ; let dt = from_ymd_opt.unwrap.and_hms_opt.unwrap.and_utc; assert_eq!;
impl Add for NaiveDateTime
fn add(self: Self, days: Days) -> <Self as >::Output
impl Add for NaiveDateTime
fn add(self: Self, rhs: TimeDelta) -> NaiveDateTime
impl Add for NaiveDateTime
fn add(self: Self, rhs: Months) -> <Self as >::Output
impl Add for NaiveDateTime
fn add(self: Self, rhs: Duration) -> NaiveDateTime
impl Add for NaiveDateTime
fn add(self: Self, rhs: FixedOffset) -> NaiveDateTime
impl AddAssign for NaiveDateTime
fn add_assign(self: &mut Self, rhs: Duration)
impl AddAssign for NaiveDateTime
fn add_assign(self: &mut Self, rhs: TimeDelta)
impl Clone for NaiveDateTime
fn clone(self: &Self) -> NaiveDateTime
impl Copy for NaiveDateTime
impl Datelike for NaiveDateTime
fn year(self: &Self) -> i32Returns the year number in the calendar date.
See also the
NaiveDate::yearmethod.Example
use ; let dt: NaiveDateTime = from_ymd_opt.unwrap.and_hms_opt.unwrap; assert_eq!;fn month(self: &Self) -> u32Returns the month number starting from 1.
The return value ranges from 1 to 12.
See also the
NaiveDate::monthmethod.Example
use ; let dt: NaiveDateTime = from_ymd_opt.unwrap.and_hms_opt.unwrap; assert_eq!;fn month0(self: &Self) -> u32Returns the month number starting from 0.
The return value ranges from 0 to 11.
See also the
NaiveDate::month0method.Example
use ; let dt: NaiveDateTime = from_ymd_opt.unwrap.and_hms_opt.unwrap; assert_eq!;fn day(self: &Self) -> u32Returns the day of month starting from 1.
The return value ranges from 1 to 31. (The last day of month differs by months.)
See also the
NaiveDate::daymethod.Example
use ; let dt: NaiveDateTime = from_ymd_opt.unwrap.and_hms_opt.unwrap; assert_eq!;fn day0(self: &Self) -> u32Returns the day of month starting from 0.
The return value ranges from 0 to 30. (The last day of month differs by months.)
See also the
NaiveDate::day0method.Example
use ; let dt: NaiveDateTime = from_ymd_opt.unwrap.and_hms_opt.unwrap; assert_eq!;fn ordinal(self: &Self) -> u32Returns the day of year starting from 1.
The return value ranges from 1 to 366. (The last day of year differs by years.)
See also the
NaiveDate::ordinalmethod.Example
use ; let dt: NaiveDateTime = from_ymd_opt.unwrap.and_hms_opt.unwrap; assert_eq!;fn ordinal0(self: &Self) -> u32Returns the day of year starting from 0.
The return value ranges from 0 to 365. (The last day of year differs by years.)
See also the
NaiveDate::ordinal0method.Example
use ; let dt: NaiveDateTime = from_ymd_opt.unwrap.and_hms_opt.unwrap; assert_eq!;fn weekday(self: &Self) -> WeekdayReturns the day of week.
See also the
NaiveDate::weekdaymethod.Example
use ; let dt: NaiveDateTime = from_ymd_opt.unwrap.and_hms_opt.unwrap; assert_eq!;fn iso_week(self: &Self) -> IsoWeekfn with_year(self: &Self, year: i32) -> Option<NaiveDateTime>Makes a new
NaiveDateTimewith the year number changed, while keeping the same month and day.See also the
NaiveDate::with_yearmethod.Errors
Returns
Noneif:- The resulting date does not exist (February 29 in a non-leap year).
- The year is out of range for a
NaiveDate.
Example
use ; let dt: NaiveDateTime = from_ymd_opt.unwrap.and_hms_opt.unwrap; assert_eq!; assert_eq!;fn with_month(self: &Self, month: u32) -> Option<NaiveDateTime>Makes a new
NaiveDateTimewith the month number (starting from 1) changed.Don't combine multiple
Datelike::with_*methods. The intermediate value may not exist.See also the
NaiveDate::with_monthmethod.Errors
Returns
Noneif:- The resulting date does not exist (for example
month(4)when day of the month is 31). - The value for
monthis invalid.
Example
use ; let dt: NaiveDateTime = from_ymd_opt.unwrap.and_hms_opt.unwrap; assert_eq!; assert_eq!; // No month 13 assert_eq!; // No February 30- The resulting date does not exist (for example
fn with_month0(self: &Self, month0: u32) -> Option<NaiveDateTime>Makes a new
NaiveDateTimewith the month number (starting from 0) changed.See also the
NaiveDate::with_month0method.Errors
Returns
Noneif:- The resulting date does not exist (for example
month0(3)when day of the month is 31). - The value for
month0is invalid.
Example
use ; let dt: NaiveDateTime = from_ymd_opt.unwrap.and_hms_opt.unwrap; assert_eq!; assert_eq!; // No month 13 assert_eq!; // No February 30- The resulting date does not exist (for example
fn with_day(self: &Self, day: u32) -> Option<NaiveDateTime>Makes a new
NaiveDateTimewith the day of month (starting from 1) changed.See also the
NaiveDate::with_daymethod.Errors
Returns
Noneif:- The resulting date does not exist (for example
day(31)in April). - The value for
dayis invalid.
Example
use ; let dt: NaiveDateTime = from_ymd_opt.unwrap.and_hms_opt.unwrap; assert_eq!; assert_eq!; // no September 31- The resulting date does not exist (for example
fn with_day0(self: &Self, day0: u32) -> Option<NaiveDateTime>Makes a new
NaiveDateTimewith the day of month (starting from 0) changed.See also the
NaiveDate::with_day0method.Errors
Returns
Noneif:- The resulting date does not exist (for example
day(30)in April). - The value for
day0is invalid.
Example
use ; let dt: NaiveDateTime = from_ymd_opt.unwrap.and_hms_opt.unwrap; assert_eq!; assert_eq!; // no September 31- The resulting date does not exist (for example
fn with_ordinal(self: &Self, ordinal: u32) -> Option<NaiveDateTime>Makes a new
NaiveDateTimewith the day of year (starting from 1) changed.See also the
NaiveDate::with_ordinalmethod.Errors
Returns
Noneif:- The resulting date does not exist (
with_ordinal(366)in a non-leap year). - The value for
ordinalis invalid.
Example
use ; let dt: NaiveDateTime = from_ymd_opt.unwrap.and_hms_opt.unwrap; assert_eq!; assert_eq!; // 2015 had only 365 days let dt: NaiveDateTime = from_ymd_opt.unwrap.and_hms_opt.unwrap; assert_eq!; assert_eq!;- The resulting date does not exist (
fn with_ordinal0(self: &Self, ordinal0: u32) -> Option<NaiveDateTime>Makes a new
NaiveDateTimewith the day of year (starting from 0) changed.See also the
NaiveDate::with_ordinal0method.Errors
Returns
Noneif:- The resulting date does not exist (
with_ordinal0(365)in a non-leap year). - The value for
ordinal0is invalid.
Example
use ; let dt: NaiveDateTime = from_ymd_opt.unwrap.and_hms_opt.unwrap; assert_eq!; assert_eq!; // 2015 had only 365 days let dt: NaiveDateTime = from_ymd_opt.unwrap.and_hms_opt.unwrap; assert_eq!; assert_eq!;- The resulting date does not exist (
impl Debug for NaiveDateTime
fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result
impl Default for NaiveDateTime
fn default() -> Self
impl Display for NaiveDateTime
fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result
impl DurationRound for NaiveDateTime
fn duration_round(self: Self, duration: TimeDelta) -> Result<Self, <Self as >::Err>fn duration_trunc(self: Self, duration: TimeDelta) -> Result<Self, <Self as >::Err>
impl Eq for NaiveDateTime
impl Freeze for NaiveDateTime
impl From for NaiveDateTime
fn from(date: NaiveDate) -> SelfConverts a
NaiveDateto aNaiveDateTimeof the same date but at midnight.Example
use ; let nd = from_ymd_opt.unwrap; let ndt = from_ymd_opt.unwrap.and_hms_opt.unwrap; assert_eq!;
impl FromStr for NaiveDateTime
fn from_str(s: &str) -> ParseResult<NaiveDateTime>
impl Hash for NaiveDateTime
fn hash<__H: $crate::hash::Hasher>(self: &Self, state: &mut __H)
impl Ord for NaiveDateTime
fn cmp(self: &Self, other: &NaiveDateTime) -> Ordering
impl PartialEq for NaiveDateTime
fn eq(self: &Self, other: &NaiveDateTime) -> bool
impl PartialOrd for NaiveDateTime
fn partial_cmp(self: &Self, other: &NaiveDateTime) -> Option<Ordering>
impl RefUnwindSafe for NaiveDateTime
impl Send for NaiveDateTime
impl StructuralPartialEq for NaiveDateTime
impl Sub for NaiveDateTime
fn sub(self: Self, rhs: Duration) -> NaiveDateTime
impl Sub for NaiveDateTime
fn sub(self: Self, rhs: FixedOffset) -> NaiveDateTime
impl Sub for NaiveDateTime
fn sub(self: Self, rhs: TimeDelta) -> NaiveDateTime
impl Sub for NaiveDateTime
fn sub(self: Self, rhs: NaiveDateTime) -> TimeDelta
impl Sub for NaiveDateTime
fn sub(self: Self, days: Days) -> <Self as >::Output
impl Sub for NaiveDateTime
fn sub(self: Self, rhs: Months) -> <Self as >::Output
impl SubAssign for NaiveDateTime
fn sub_assign(self: &mut Self, rhs: Duration)
impl SubAssign for NaiveDateTime
fn sub_assign(self: &mut Self, rhs: TimeDelta)
impl Sync for NaiveDateTime
impl Timelike for NaiveDateTime
fn hour(self: &Self) -> u32Returns the hour number from 0 to 23.
See also the
NaiveTime::hourmethod.Example
use ; let dt: NaiveDateTime = from_ymd_opt.unwrap.and_hms_milli_opt.unwrap; assert_eq!;fn minute(self: &Self) -> u32Returns the minute number from 0 to 59.
See also the
NaiveTime::minutemethod.Example
use ; let dt: NaiveDateTime = from_ymd_opt.unwrap.and_hms_milli_opt.unwrap; assert_eq!;fn second(self: &Self) -> u32Returns the second number from 0 to 59.
See also the
NaiveTime::secondmethod.Example
use ; let dt: NaiveDateTime = from_ymd_opt.unwrap.and_hms_milli_opt.unwrap; assert_eq!;fn nanosecond(self: &Self) -> u32Returns the number of nanoseconds since the whole non-leap second. The range from 1,000,000,000 to 1,999,999,999 represents the leap second.
See also the [
NaiveTime#method.nanosecond] method.Example
use ; let dt: NaiveDateTime = from_ymd_opt.unwrap.and_hms_milli_opt.unwrap; assert_eq!;fn with_hour(self: &Self, hour: u32) -> Option<NaiveDateTime>Makes a new
NaiveDateTimewith the hour number changed.See also the
NaiveTime::with_hourmethod.Errors
Returns
Noneif the value forhouris invalid.Example
use ; let dt: NaiveDateTime = from_ymd_opt.unwrap.and_hms_milli_opt.unwrap; assert_eq!; assert_eq!;fn with_minute(self: &Self, min: u32) -> Option<NaiveDateTime>Makes a new
NaiveDateTimewith the minute number changed.See also the
NaiveTime::with_minutemethod.Errors
Returns
Noneif the value forminuteis invalid.Example
use ; let dt: NaiveDateTime = from_ymd_opt.unwrap.and_hms_milli_opt.unwrap; assert_eq!; assert_eq!;fn with_second(self: &Self, sec: u32) -> Option<NaiveDateTime>Makes a new
NaiveDateTimewith the second number changed.As with the
secondmethod, the input range is restricted to 0 through 59.See also the
NaiveTime::with_secondmethod.Errors
Returns
Noneif the value forsecondis invalid.Example
use ; let dt: NaiveDateTime = from_ymd_opt.unwrap.and_hms_milli_opt.unwrap; assert_eq!; assert_eq!;fn with_nanosecond(self: &Self, nano: u32) -> Option<NaiveDateTime>Makes a new
NaiveDateTimewith nanoseconds since the whole non-leap second changed.Returns
Nonewhen the resultingNaiveDateTimewould be invalid. As with theNaiveDateTime::nanosecondmethod, the input range can exceed 1,000,000,000 for leap seconds.See also the
NaiveTime::with_nanosecondmethod.Errors
Returns
Noneifnanosecond >= 2,000,000,000.Example
use ; let dt: NaiveDateTime = from_ymd_opt.unwrap.and_hms_milli_opt.unwrap; assert_eq!; assert_eq!; assert_eq!;
impl Unpin for NaiveDateTime
impl UnsafeUnpin for NaiveDateTime
impl UnwindSafe for NaiveDateTime
impl<T> Any for NaiveDateTime
fn type_id(self: &Self) -> TypeId
impl<T> Borrow for NaiveDateTime
fn borrow(self: &Self) -> &T
impl<T> BorrowMut for NaiveDateTime
fn borrow_mut(self: &mut Self) -> &mut T
impl<T> CloneToUninit for NaiveDateTime
unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)
impl<T> From for NaiveDateTime
fn from(t: T) -> TReturns the argument unchanged.
impl<T> SubsecRound for NaiveDateTime
fn round_subsecs(self: Self, digits: u16) -> Tfn trunc_subsecs(self: Self, digits: u16) -> T
impl<T> ToOwned for NaiveDateTime
fn to_owned(self: &Self) -> Tfn clone_into(self: &Self, target: &mut T)
impl<T> ToString for NaiveDateTime
fn to_string(self: &Self) -> String
impl<T, U> Into for NaiveDateTime
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 NaiveDateTime
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto for NaiveDateTime
fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>