blob: 9085f3b9c8fc4e492cb8f0071394ffd47a984667 [file] [log] [blame]
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="ISO 8601 combined date and time without timezone."><meta name="keywords" content="rust, rustlang, rust-lang, NaiveDateTime"><title>NaiveDateTime in chrono::naive - Rust</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../../SourceSerif4-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../FiraSans-Regular.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../FiraSans-Medium.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../SourceCodePro-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../SourceSerif4-Bold.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../SourceCodePro-Semibold.ttf.woff2"><link rel="stylesheet" href="../../normalize.css"><link rel="stylesheet" href="../../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" href="../../ayu.css" disabled><link rel="stylesheet" href="../../dark.css" disabled><link rel="stylesheet" href="../../light.css" id="themeStyle"><script id="default-settings" ></script><script src="../../storage.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../main.js"></script><noscript><link rel="stylesheet" href="../../noscript.css"></noscript><link rel="alternate icon" type="image/png" href="../../favicon-16x16.png"><link rel="alternate icon" type="image/png" href="../../favicon-32x32.png"><link rel="icon" type="image/svg+xml" href="../../favicon.svg"></head><body class="rustdoc struct"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle">&#9776;</button><a class="sidebar-logo" href="../../chrono/index.html"><div class="logo-container"><img class="rust-logo" src="../../rust-logo.svg" alt="logo"></div></a><h2></h2></nav><nav class="sidebar"><a class="sidebar-logo" href="../../chrono/index.html"><div class="logo-container"><img class="rust-logo" src="../../rust-logo.svg" alt="logo"></div></a><h2 class="location"><a href="#">NaiveDateTime</a></h2><div class="sidebar-elems"><section><h3><a href="#implementations">Associated Constants</a></h3><ul class="block"><li><a href="#associatedconstant.MAX">MAX</a></li><li><a href="#associatedconstant.MIN">MIN</a></li></ul><h3><a href="#implementations">Methods</a></h3><ul class="block"><li><a href="#method.and_local_timezone">and_local_timezone</a></li><li><a href="#method.and_utc">and_utc</a></li><li><a href="#method.checked_add_days">checked_add_days</a></li><li><a href="#method.checked_add_months">checked_add_months</a></li><li><a href="#method.checked_add_signed">checked_add_signed</a></li><li><a href="#method.checked_sub_days">checked_sub_days</a></li><li><a href="#method.checked_sub_months">checked_sub_months</a></li><li><a href="#method.checked_sub_signed">checked_sub_signed</a></li><li><a href="#method.date">date</a></li><li><a href="#method.format">format</a></li><li><a href="#method.format_with_items">format_with_items</a></li><li><a href="#method.from_timestamp">from_timestamp</a></li><li><a href="#method.from_timestamp_micros">from_timestamp_micros</a></li><li><a href="#method.from_timestamp_millis">from_timestamp_millis</a></li><li><a href="#method.from_timestamp_opt">from_timestamp_opt</a></li><li><a href="#method.new">new</a></li><li><a href="#method.parse_and_remainder">parse_and_remainder</a></li><li><a href="#method.parse_from_str">parse_from_str</a></li><li><a href="#method.signed_duration_since">signed_duration_since</a></li><li><a href="#method.time">time</a></li><li><a href="#method.timestamp">timestamp</a></li><li><a href="#method.timestamp_micros">timestamp_micros</a></li><li><a href="#method.timestamp_millis">timestamp_millis</a></li><li><a href="#method.timestamp_nanos">timestamp_nanos</a></li><li><a href="#method.timestamp_subsec_micros">timestamp_subsec_micros</a></li><li><a href="#method.timestamp_subsec_millis">timestamp_subsec_millis</a></li><li><a href="#method.timestamp_subsec_nanos">timestamp_subsec_nanos</a></li></ul><h3><a href="#trait-implementations">Trait Implementations</a></h3><ul class="block"><li><a href="#impl-Add%3CDays%3E-for-NaiveDateTime">Add&lt;Days&gt;</a></li><li><a href="#impl-Add%3CDuration%3E-for-NaiveDateTime">Add&lt;Duration&gt;</a></li><li><a href="#impl-Add%3CFixedOffset%3E-for-NaiveDateTime">Add&lt;FixedOffset&gt;</a></li><li><a href="#impl-Add%3CMonths%3E-for-NaiveDateTime">Add&lt;Months&gt;</a></li><li><a href="#impl-AddAssign%3CDuration%3E-for-NaiveDateTime">AddAssign&lt;Duration&gt;</a></li><li><a href="#impl-Clone-for-NaiveDateTime">Clone</a></li><li><a href="#impl-Copy-for-NaiveDateTime">Copy</a></li><li><a href="#impl-Datelike-for-NaiveDateTime">Datelike</a></li><li><a href="#impl-Debug-for-NaiveDateTime">Debug</a></li><li><a href="#impl-Default-for-NaiveDateTime">Default</a></li><li><a href="#impl-Display-for-NaiveDateTime">Display</a></li><li><a href="#impl-DurationRound-for-NaiveDateTime">DurationRound</a></li><li><a href="#impl-Eq-for-NaiveDateTime">Eq</a></li><li><a href="#impl-From%3CNaiveDateTime%3E-for-NaiveDate">From&lt;NaiveDateTime&gt;</a></li><li><a href="#impl-FromStr-for-NaiveDateTime">FromStr</a></li><li><a href="#impl-Hash-for-NaiveDateTime">Hash</a></li><li><a href="#impl-Ord-for-NaiveDateTime">Ord</a></li><li><a href="#impl-PartialEq%3CNaiveDateTime%3E-for-NaiveDateTime">PartialEq&lt;NaiveDateTime&gt;</a></li><li><a href="#impl-PartialOrd%3CNaiveDateTime%3E-for-NaiveDateTime">PartialOrd&lt;NaiveDateTime&gt;</a></li><li><a href="#impl-StructuralEq-for-NaiveDateTime">StructuralEq</a></li><li><a href="#impl-StructuralPartialEq-for-NaiveDateTime">StructuralPartialEq</a></li><li><a href="#impl-Sub%3CDays%3E-for-NaiveDateTime">Sub&lt;Days&gt;</a></li><li><a href="#impl-Sub%3CDuration%3E-for-NaiveDateTime">Sub&lt;Duration&gt;</a></li><li><a href="#impl-Sub%3CFixedOffset%3E-for-NaiveDateTime">Sub&lt;FixedOffset&gt;</a></li><li><a href="#impl-Sub%3CMonths%3E-for-NaiveDateTime">Sub&lt;Months&gt;</a></li><li><a href="#impl-Sub%3CNaiveDateTime%3E-for-NaiveDateTime">Sub&lt;NaiveDateTime&gt;</a></li><li><a href="#impl-SubAssign%3CDuration%3E-for-NaiveDateTime">SubAssign&lt;Duration&gt;</a></li><li><a href="#impl-Timelike-for-NaiveDateTime">Timelike</a></li></ul><h3><a href="#synthetic-implementations">Auto Trait Implementations</a></h3><ul class="block"><li><a href="#impl-RefUnwindSafe-for-NaiveDateTime">RefUnwindSafe</a></li><li><a href="#impl-Send-for-NaiveDateTime">Send</a></li><li><a href="#impl-Sync-for-NaiveDateTime">Sync</a></li><li><a href="#impl-Unpin-for-NaiveDateTime">Unpin</a></li><li><a href="#impl-UnwindSafe-for-NaiveDateTime">UnwindSafe</a></li></ul><h3><a href="#blanket-implementations">Blanket Implementations</a></h3><ul class="block"><li><a href="#impl-Any-for-NaiveDateTime">Any</a></li><li><a href="#impl-Borrow%3CT%3E-for-NaiveDateTime">Borrow&lt;T&gt;</a></li><li><a href="#impl-BorrowMut%3CT%3E-for-NaiveDateTime">BorrowMut&lt;T&gt;</a></li><li><a href="#impl-From%3CT%3E-for-NaiveDateTime">From&lt;T&gt;</a></li><li><a href="#impl-Into%3CU%3E-for-NaiveDateTime">Into&lt;U&gt;</a></li><li><a href="#impl-ToOwned-for-NaiveDateTime">ToOwned</a></li><li><a href="#impl-ToString-for-NaiveDateTime">ToString</a></li><li><a href="#impl-TryFrom%3CU%3E-for-NaiveDateTime">TryFrom&lt;U&gt;</a></li><li><a href="#impl-TryInto%3CU%3E-for-NaiveDateTime">TryInto&lt;U&gt;</a></li></ul></section><h2><a href="index.html">In chrono::naive</a></h2></div></nav><main><div class="width-limiter"><nav class="sub"><form class="search-form"><div class="search-container"><span></span><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><div id="help-button" title="help" tabindex="-1"><a href="../../help.html">?</a></div><div id="settings-menu" tabindex="-1"><a href="../../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../../wheel.svg"></a></div></div></form></nav><section id="main-content" class="content"><div class="main-heading"><h1 class="fqn">Struct <a href="../index.html">chrono</a>::<wbr><a href="index.html">naive</a>::<wbr><a class="struct" href="#">NaiveDateTime</a><button id="copy-path" onclick="copy_path(this)" title="Copy item path to clipboard"><img src="../../clipboard.svg" width="19" height="18" alt="Copy item path"></button></h1><span class="out-of-band"><a class="srclink" href="../../src/chrono/naive/datetime/mod.rs.html#77-80">source</a> · <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">&#x2212;</span>]</a></span></div><div class="item-decl"><pre class="rust struct"><code>pub struct NaiveDateTime { /* private fields */ }</code></pre></div><details class="rustdoc-toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>ISO 8601 combined date and time without timezone.</p>
<h2 id="example"><a href="#example">Example</a></h2>
<p><code>NaiveDateTime</code> is commonly created from <a href="./struct.NaiveDate.html"><code>NaiveDate</code></a>.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>chrono::{NaiveDate, NaiveDateTime};
<span class="kw">let </span>dt: NaiveDateTime = NaiveDate::from_ymd_opt(<span class="number">2016</span>, <span class="number">7</span>, <span class="number">8</span>).unwrap().and_hms_opt(<span class="number">9</span>, <span class="number">10</span>, <span class="number">11</span>).unwrap();</code></pre></div>
<p>You can use typical <a href="../trait.Datelike.html">date-like</a> and
<a href="../trait.Timelike.html">time-like</a> methods,
provided that relevant traits are in the scope.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>chrono::{Datelike, Timelike, Weekday};
<span class="macro">assert_eq!</span>(dt.weekday(), Weekday::Fri);
<span class="macro">assert_eq!</span>(dt.num_seconds_from_midnight(), <span class="number">33011</span>);</code></pre></div>
</div></details><h2 id="implementations" class="small-section-header">Implementations<a href="#implementations" class="anchor"></a></h2><div id="implementations-list"><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-NaiveDateTime" class="impl has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#82-942">source</a><a href="#impl-NaiveDateTime" class="anchor"></a><h3 class="code-header">impl <a class="struct" href="struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.new" class="method has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#100-102">source</a><h4 class="code-header">pub const fn <a href="#method.new" class="fnname">new</a>(date: <a class="struct" href="struct.NaiveDate.html" title="struct chrono::naive::NaiveDate">NaiveDate</a>, time: <a class="struct" href="struct.NaiveTime.html" title="struct chrono::naive::NaiveTime">NaiveTime</a>) -&gt; <a class="struct" href="struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a></h4></section></summary><div class="docblock"><p>Makes a new <code>NaiveDateTime</code> from date and time components.
Equivalent to <a href="./struct.NaiveDate.html#method.and_time"><code>date.and_time(time)</code></a>
and many other helper constructors on <code>NaiveDate</code>.</p>
<h5 id="example-1"><a href="#example-1">Example</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>chrono::{NaiveDate, NaiveTime, NaiveDateTime};
<span class="kw">let </span>d = NaiveDate::from_ymd_opt(<span class="number">2015</span>, <span class="number">6</span>, <span class="number">3</span>).unwrap();
<span class="kw">let </span>t = NaiveTime::from_hms_milli_opt(<span class="number">12</span>, <span class="number">34</span>, <span class="number">56</span>, <span class="number">789</span>).unwrap();
<span class="kw">let </span>dt = NaiveDateTime::new(d, t);
<span class="macro">assert_eq!</span>(dt.date(), d);
<span class="macro">assert_eq!</span>(dt.time(), t);</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.from_timestamp" class="method has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#120-123">source</a><h4 class="code-header">pub fn <a href="#method.from_timestamp" class="fnname">from_timestamp</a>(secs: i64, nsecs: u32) -&gt; <a class="struct" href="struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a></h4></section><span class="item-info"><div class="stab deprecated"><span class="emoji">👎</span><span>Deprecated since 0.4.23: use <code>from_timestamp_opt()</code> instead</span></div></span></summary><div class="docblock"><p>Makes a new <code>NaiveDateTime</code> corresponding 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.</p>
<p>For a non-naive version of this function see
<a href="../offset/trait.TimeZone.html#method.timestamp"><code>TimeZone::timestamp</code></a>.</p>
<p>The nanosecond part can exceed 1,000,000,000 in order to represent the
<a href="./struct.NaiveTime.html#leap-second-handling">leap second</a>. (The true “UNIX
timestamp” cannot represent a leap second unambiguously.)</p>
<p>Panics on the out-of-range number of seconds and/or invalid nanosecond.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.from_timestamp_millis" class="method has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#148-152">source</a><h4 class="code-header">pub fn <a href="#method.from_timestamp_millis" class="fnname">from_timestamp_millis</a>(millis: i64) -&gt; Option&lt;<a class="struct" href="struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a>&gt;</h4></section></summary><div class="docblock"><p>Creates a new <a href="struct.NaiveDateTime.html" title="NaiveDateTime">NaiveDateTime</a> from milliseconds since the UNIX epoch.</p>
<p>The UNIX epoch starts on midnight, January 1, 1970, UTC.</p>
<p>Returns <code>None</code> on an out-of-range number of milliseconds.</p>
<h5 id="example-2"><a href="#example-2">Example</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>chrono::NaiveDateTime;
<span class="kw">let </span>timestamp_millis: i64 = <span class="number">1662921288000</span>; <span class="comment">//Sunday, September 11, 2022 6:34:48 PM
</span><span class="kw">let </span>naive_datetime = NaiveDateTime::from_timestamp_millis(timestamp_millis);
<span class="macro">assert!</span>(naive_datetime.is_some());
<span class="macro">assert_eq!</span>(timestamp_millis, naive_datetime.unwrap().timestamp_millis());
<span class="comment">// Negative timestamps (before the UNIX epoch) are supported as well.
</span><span class="kw">let </span>timestamp_millis: i64 = -<span class="number">2208936075000</span>; <span class="comment">//Mon Jan 01 1900 14:38:45 GMT+0000
</span><span class="kw">let </span>naive_datetime = NaiveDateTime::from_timestamp_millis(timestamp_millis);
<span class="macro">assert!</span>(naive_datetime.is_some());
<span class="macro">assert_eq!</span>(timestamp_millis, naive_datetime.unwrap().timestamp_millis());</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.from_timestamp_micros" class="method has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#177-181">source</a><h4 class="code-header">pub fn <a href="#method.from_timestamp_micros" class="fnname">from_timestamp_micros</a>(micros: i64) -&gt; Option&lt;<a class="struct" href="struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a>&gt;</h4></section></summary><div class="docblock"><p>Creates a new <a href="struct.NaiveDateTime.html" title="NaiveDateTime">NaiveDateTime</a> from microseconds since the UNIX epoch.</p>
<p>The UNIX epoch starts on midnight, January 1, 1970, UTC.</p>
<p>Returns <code>None</code> on an out-of-range number of microseconds.</p>
<h5 id="example-3"><a href="#example-3">Example</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>chrono::NaiveDateTime;
<span class="kw">let </span>timestamp_micros: i64 = <span class="number">1662921288000000</span>; <span class="comment">//Sunday, September 11, 2022 6:34:48 PM
</span><span class="kw">let </span>naive_datetime = NaiveDateTime::from_timestamp_micros(timestamp_micros);
<span class="macro">assert!</span>(naive_datetime.is_some());
<span class="macro">assert_eq!</span>(timestamp_micros, naive_datetime.unwrap().timestamp_micros());
<span class="comment">// Negative timestamps (before the UNIX epoch) are supported as well.
</span><span class="kw">let </span>timestamp_micros: i64 = -<span class="number">2208936075000000</span>; <span class="comment">//Mon Jan 01 1900 14:38:45 GMT+0000
</span><span class="kw">let </span>naive_datetime = NaiveDateTime::from_timestamp_micros(timestamp_micros);
<span class="macro">assert!</span>(naive_datetime.is_some());
<span class="macro">assert_eq!</span>(timestamp_micros, naive_datetime.unwrap().timestamp_micros());</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.from_timestamp_opt" class="method has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#211-223">source</a><h4 class="code-header">pub fn <a href="#method.from_timestamp_opt" class="fnname">from_timestamp_opt</a>(secs: i64, nsecs: u32) -&gt; Option&lt;<a class="struct" href="struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a>&gt;</h4></section></summary><div class="docblock"><p>Makes a new <code>NaiveDateTime</code> corresponding 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.</p>
<p>The nanosecond part can exceed 1,000,000,000
in order to represent the <a href="./struct.NaiveTime.html#leap-second-handling">leap second</a>.
(The true “UNIX timestamp” cannot represent a leap second unambiguously.)</p>
<p>Returns <code>None</code> on the out-of-range number of seconds (more than 262 000 years away
from common era) and/or invalid nanosecond (2 seconds or more).</p>
<h5 id="example-4"><a href="#example-4">Example</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>chrono::NaiveDateTime;
<span class="kw">use </span>std::i64;
<span class="kw">let </span>from_timestamp_opt = NaiveDateTime::from_timestamp_opt;
<span class="macro">assert!</span>(from_timestamp_opt(<span class="number">0</span>, <span class="number">0</span>).is_some());
<span class="macro">assert!</span>(from_timestamp_opt(<span class="number">0</span>, <span class="number">999_999_999</span>).is_some());
<span class="macro">assert!</span>(from_timestamp_opt(<span class="number">0</span>, <span class="number">1_500_000_000</span>).is_some()); <span class="comment">// leap second
</span><span class="macro">assert!</span>(from_timestamp_opt(<span class="number">0</span>, <span class="number">2_000_000_000</span>).is_none());
<span class="macro">assert!</span>(from_timestamp_opt(i64::MAX, <span class="number">0</span>).is_none());</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.parse_from_str" class="method has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#296-300">source</a><h4 class="code-header">pub fn <a href="#method.parse_from_str" class="fnname">parse_from_str</a>(s: &amp;str, fmt: &amp;str) -&gt; <a class="type" href="../format/type.ParseResult.html" title="type chrono::format::ParseResult">ParseResult</a>&lt;<a class="struct" href="struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a>&gt;</h4></section></summary><div class="docblock"><p>Parses a string with the specified format string and returns a new <code>NaiveDateTime</code>.
See the <a href="../format/strftime/index.html"><code>format::strftime</code> module</a>
on the supported escape sequences.</p>
<h5 id="example-5"><a href="#example-5">Example</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>chrono::{NaiveDateTime, NaiveDate};
<span class="kw">let </span>parse_from_str = NaiveDateTime::parse_from_str;
<span class="macro">assert_eq!</span>(parse_from_str(<span class="string">&quot;2015-09-05 23:56:04&quot;</span>, <span class="string">&quot;%Y-%m-%d %H:%M:%S&quot;</span>),
<span class="prelude-val">Ok</span>(NaiveDate::from_ymd_opt(<span class="number">2015</span>, <span class="number">9</span>, <span class="number">5</span>).unwrap().and_hms_opt(<span class="number">23</span>, <span class="number">56</span>, <span class="number">4</span>).unwrap()));
<span class="macro">assert_eq!</span>(parse_from_str(<span class="string">&quot;5sep2015pm012345.6789&quot;</span>, <span class="string">&quot;%d%b%Y%p%I%M%S%.f&quot;</span>),
<span class="prelude-val">Ok</span>(NaiveDate::from_ymd_opt(<span class="number">2015</span>, <span class="number">9</span>, <span class="number">5</span>).unwrap().and_hms_micro_opt(<span class="number">13</span>, <span class="number">23</span>, <span class="number">45</span>, <span class="number">678_900</span>).unwrap()));</code></pre></div>
<p>Offset is ignored for the purpose of parsing.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="macro">assert_eq!</span>(parse_from_str(<span class="string">&quot;2014-5-17T12:34:56+09:30&quot;</span>, <span class="string">&quot;%Y-%m-%dT%H:%M:%S%z&quot;</span>),
<span class="prelude-val">Ok</span>(NaiveDate::from_ymd_opt(<span class="number">2014</span>, <span class="number">5</span>, <span class="number">17</span>).unwrap().and_hms_opt(<span class="number">12</span>, <span class="number">34</span>, <span class="number">56</span>).unwrap()));</code></pre></div>
<p><a href="./struct.NaiveTime.html#leap-second-handling">Leap seconds</a> are correctly handled by
treating any time of the form <code>hh:mm:60</code> as a leap second.
(This equally applies to the formatting, so the round trip is possible.)</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="macro">assert_eq!</span>(parse_from_str(<span class="string">&quot;2015-07-01 08:59:60.123&quot;</span>, <span class="string">&quot;%Y-%m-%d %H:%M:%S%.f&quot;</span>),
<span class="prelude-val">Ok</span>(NaiveDate::from_ymd_opt(<span class="number">2015</span>, <span class="number">7</span>, <span class="number">1</span>).unwrap().and_hms_milli_opt(<span class="number">8</span>, <span class="number">59</span>, <span class="number">59</span>, <span class="number">1_123</span>).unwrap()));</code></pre></div>
<p>Missing seconds are assumed to be zero,
but out-of-bound times or insufficient fields are errors otherwise.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="macro">assert_eq!</span>(parse_from_str(<span class="string">&quot;94/9/4 7:15&quot;</span>, <span class="string">&quot;%y/%m/%d %H:%M&quot;</span>),
<span class="prelude-val">Ok</span>(NaiveDate::from_ymd_opt(<span class="number">1994</span>, <span class="number">9</span>, <span class="number">4</span>).unwrap().and_hms_opt(<span class="number">7</span>, <span class="number">15</span>, <span class="number">0</span>).unwrap()));
<span class="macro">assert!</span>(parse_from_str(<span class="string">&quot;04m33s&quot;</span>, <span class="string">&quot;%Mm%Ss&quot;</span>).is_err());
<span class="macro">assert!</span>(parse_from_str(<span class="string">&quot;94/9/4 12&quot;</span>, <span class="string">&quot;%y/%m/%d %H&quot;</span>).is_err());
<span class="macro">assert!</span>(parse_from_str(<span class="string">&quot;94/9/4 17:60&quot;</span>, <span class="string">&quot;%y/%m/%d %H:%M&quot;</span>).is_err());
<span class="macro">assert!</span>(parse_from_str(<span class="string">&quot;94/9/4 24:00:00&quot;</span>, <span class="string">&quot;%y/%m/%d %H:%M:%S&quot;</span>).is_err());</code></pre></div>
<p>All parsed fields should be consistent to each other, otherwise it’s an error.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>fmt = <span class="string">&quot;%Y-%m-%d %H:%M:%S = UNIX timestamp %s&quot;</span>;
<span class="macro">assert!</span>(parse_from_str(<span class="string">&quot;2001-09-09 01:46:39 = UNIX timestamp 999999999&quot;</span>, fmt).is_ok());
<span class="macro">assert!</span>(parse_from_str(<span class="string">&quot;1970-01-01 00:00:00 = UNIX timestamp 1&quot;</span>, fmt).is_err());</code></pre></div>
<p>Years before 1 BCE or after 9999 CE, require an initial sign</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code> <span class="kw">let </span>fmt = <span class="string">&quot;%Y-%m-%d %H:%M:%S&quot;</span>;
<span class="macro">assert!</span>(parse_from_str(<span class="string">&quot;10000-09-09 01:46:39&quot;</span>, fmt).is_err());
<span class="macro">assert!</span>(parse_from_str(<span class="string">&quot;+10000-09-09 01:46:39&quot;</span>, fmt).is_ok());</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.parse_and_remainder" class="method has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#321-325">source</a><h4 class="code-header">pub fn <a href="#method.parse_and_remainder" class="fnname">parse_and_remainder</a>&lt;'a&gt;(<br>&nbsp;&nbsp;&nbsp;&nbsp;s: &amp;'a str,<br>&nbsp;&nbsp;&nbsp;&nbsp;fmt: &amp;str<br>) -&gt; <a class="type" href="../format/type.ParseResult.html" title="type chrono::format::ParseResult">ParseResult</a>&lt;(<a class="struct" href="struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a>, &amp;'a str)&gt;</h4></section></summary><div class="docblock"><p>Parses a string with the specified format string and returns a new <code>NaiveDateTime</code>, and a
slice with the remaining portion of the string.
See the <a href="../format/strftime/index.html"><code>format::strftime</code> module</a>
on the supported escape sequences.</p>
<p>Similar to <a href="#method.parse_from_str"><code>parse_from_str</code></a>.</p>
<h5 id="example-6"><a href="#example-6">Example</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>(datetime, remainder) = NaiveDateTime::parse_and_remainder(
<span class="string">&quot;2015-02-18 23:16:09 trailing text&quot;</span>, <span class="string">&quot;%Y-%m-%d %H:%M:%S&quot;</span>).unwrap();
<span class="macro">assert_eq!</span>(
datetime,
NaiveDate::from_ymd_opt(<span class="number">2015</span>, <span class="number">2</span>, <span class="number">18</span>).unwrap().and_hms_opt(<span class="number">23</span>, <span class="number">16</span>, <span class="number">9</span>).unwrap()
);
<span class="macro">assert_eq!</span>(remainder, <span class="string">&quot; trailing text&quot;</span>);</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.date" class="method has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#338-340">source</a><h4 class="code-header">pub const fn <a href="#method.date" class="fnname">date</a>(&amp;self) -&gt; <a class="struct" href="struct.NaiveDate.html" title="struct chrono::naive::NaiveDate">NaiveDate</a></h4></section></summary><div class="docblock"><p>Retrieves a date component.</p>
<h5 id="example-7"><a href="#example-7">Example</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>chrono::NaiveDate;
<span class="kw">let </span>dt = NaiveDate::from_ymd_opt(<span class="number">2016</span>, <span class="number">7</span>, <span class="number">8</span>).unwrap().and_hms_opt(<span class="number">9</span>, <span class="number">10</span>, <span class="number">11</span>).unwrap();
<span class="macro">assert_eq!</span>(dt.date(), NaiveDate::from_ymd_opt(<span class="number">2016</span>, <span class="number">7</span>, <span class="number">8</span>).unwrap());</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.time" class="method has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#353-355">source</a><h4 class="code-header">pub const fn <a href="#method.time" class="fnname">time</a>(&amp;self) -&gt; <a class="struct" href="struct.NaiveTime.html" title="struct chrono::naive::NaiveTime">NaiveTime</a></h4></section></summary><div class="docblock"><p>Retrieves a time component.</p>
<h5 id="example-8"><a href="#example-8">Example</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>chrono::{NaiveDate, NaiveTime};
<span class="kw">let </span>dt = NaiveDate::from_ymd_opt(<span class="number">2016</span>, <span class="number">7</span>, <span class="number">8</span>).unwrap().and_hms_opt(<span class="number">9</span>, <span class="number">10</span>, <span class="number">11</span>).unwrap();
<span class="macro">assert_eq!</span>(dt.time(), NaiveTime::from_hms_opt(<span class="number">9</span>, <span class="number">10</span>, <span class="number">11</span>).unwrap());</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.timestamp" class="method has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#381-386">source</a><h4 class="code-header">pub fn <a href="#method.timestamp" class="fnname">timestamp</a>(&amp;self) -&gt; i64</h4></section></summary><div class="docblock"><p>Returns the number of non-leap seconds since the midnight on January 1, 1970.</p>
<p>Note that this does <em>not</em> account for the timezone!
The true “UNIX timestamp” would count seconds since the midnight <em>UTC</em> on the epoch.</p>
<h5 id="example-9"><a href="#example-9">Example</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>chrono::NaiveDate;
<span class="kw">let </span>dt = NaiveDate::from_ymd_opt(<span class="number">1970</span>, <span class="number">1</span>, <span class="number">1</span>).unwrap().and_hms_milli_opt(<span class="number">0</span>, <span class="number">0</span>, <span class="number">1</span>, <span class="number">980</span>).unwrap();
<span class="macro">assert_eq!</span>(dt.timestamp(), <span class="number">1</span>);
<span class="kw">let </span>dt = NaiveDate::from_ymd_opt(<span class="number">2001</span>, <span class="number">9</span>, <span class="number">9</span>).unwrap().and_hms_opt(<span class="number">1</span>, <span class="number">46</span>, <span class="number">40</span>).unwrap();
<span class="macro">assert_eq!</span>(dt.timestamp(), <span class="number">1_000_000_000</span>);
<span class="kw">let </span>dt = NaiveDate::from_ymd_opt(<span class="number">1969</span>, <span class="number">12</span>, <span class="number">31</span>).unwrap().and_hms_opt(<span class="number">23</span>, <span class="number">59</span>, <span class="number">59</span>).unwrap();
<span class="macro">assert_eq!</span>(dt.timestamp(), -<span class="number">1</span>);
<span class="kw">let </span>dt = NaiveDate::from_ymd_opt(-<span class="number">1</span>, <span class="number">1</span>, <span class="number">1</span>).unwrap().and_hms_opt(<span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>).unwrap();
<span class="macro">assert_eq!</span>(dt.timestamp(), -<span class="number">62198755200</span>);</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.timestamp_millis" class="method has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#414-417">source</a><h4 class="code-header">pub fn <a href="#method.timestamp_millis" class="fnname">timestamp_millis</a>(&amp;self) -&gt; i64</h4></section></summary><div class="docblock"><p>Returns the number of non-leap <em>milliseconds</em> since midnight on January 1, 1970.</p>
<p>Note that this does <em>not</em> account for the timezone!
The true “UNIX timestamp” would count seconds since the midnight <em>UTC</em> on the epoch.</p>
<p>Note also that this does reduce the number of years that can be
represented from ~584 Billion to ~584 Million. (If this is a problem,
please file an issue to let me know what domain needs millisecond
precision over billions of years, I’m curious.)</p>
<h5 id="example-10"><a href="#example-10">Example</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>chrono::NaiveDate;
<span class="kw">let </span>dt = NaiveDate::from_ymd_opt(<span class="number">1970</span>, <span class="number">1</span>, <span class="number">1</span>).unwrap().and_hms_milli_opt(<span class="number">0</span>, <span class="number">0</span>, <span class="number">1</span>, <span class="number">444</span>).unwrap();
<span class="macro">assert_eq!</span>(dt.timestamp_millis(), <span class="number">1_444</span>);
<span class="kw">let </span>dt = NaiveDate::from_ymd_opt(<span class="number">2001</span>, <span class="number">9</span>, <span class="number">9</span>).unwrap().and_hms_milli_opt(<span class="number">1</span>, <span class="number">46</span>, <span class="number">40</span>, <span class="number">555</span>).unwrap();
<span class="macro">assert_eq!</span>(dt.timestamp_millis(), <span class="number">1_000_000_000_555</span>);
<span class="kw">let </span>dt = NaiveDate::from_ymd_opt(<span class="number">1969</span>, <span class="number">12</span>, <span class="number">31</span>).unwrap().and_hms_milli_opt(<span class="number">23</span>, <span class="number">59</span>, <span class="number">59</span>, <span class="number">100</span>).unwrap();
<span class="macro">assert_eq!</span>(dt.timestamp_millis(), -<span class="number">900</span>);</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.timestamp_micros" class="method has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#442-445">source</a><h4 class="code-header">pub fn <a href="#method.timestamp_micros" class="fnname">timestamp_micros</a>(&amp;self) -&gt; i64</h4></section></summary><div class="docblock"><p>Returns the number of non-leap <em>microseconds</em> since midnight on January 1, 1970.</p>
<p>Note that this does <em>not</em> account for the timezone!
The true “UNIX timestamp” would count seconds since the midnight <em>UTC</em> on the epoch.</p>
<p>Note also that this does reduce the number of years that can be
represented from ~584 Billion to ~584 Thousand. (If this is a problem,
please file an issue to let me know what domain needs microsecond
precision over millennia, I’m curious.)</p>
<h5 id="example-11"><a href="#example-11">Example</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>chrono::NaiveDate;
<span class="kw">let </span>dt = NaiveDate::from_ymd_opt(<span class="number">1970</span>, <span class="number">1</span>, <span class="number">1</span>).unwrap().and_hms_micro_opt(<span class="number">0</span>, <span class="number">0</span>, <span class="number">1</span>, <span class="number">444</span>).unwrap();
<span class="macro">assert_eq!</span>(dt.timestamp_micros(), <span class="number">1_000_444</span>);
<span class="kw">let </span>dt = NaiveDate::from_ymd_opt(<span class="number">2001</span>, <span class="number">9</span>, <span class="number">9</span>).unwrap().and_hms_micro_opt(<span class="number">1</span>, <span class="number">46</span>, <span class="number">40</span>, <span class="number">555</span>).unwrap();
<span class="macro">assert_eq!</span>(dt.timestamp_micros(), <span class="number">1_000_000_000_000_555</span>);</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.timestamp_nanos" class="method has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#482-485">source</a><h4 class="code-header">pub fn <a href="#method.timestamp_nanos" class="fnname">timestamp_nanos</a>(&amp;self) -&gt; i64</h4></section></summary><div class="docblock"><p>Returns the number of non-leap <em>nanoseconds</em> since midnight on January 1, 1970.</p>
<p>Note that this does <em>not</em> account for the timezone!
The true “UNIX timestamp” would count seconds since the midnight <em>UTC</em> on the epoch.</p>
<h5 id="panics"><a href="#panics">Panics</a></h5>
<p>Note also that this does reduce the number of years that can be
represented from ~584 Billion to ~584 years. The dates that can be
represented as nanoseconds are between 1677-09-21T00:12:44.0 and
2262-04-11T23:47:16.854775804.</p>
<p>(If this is a problem, please file an issue to let me know what domain
needs nanosecond precision over millennia, I’m curious.)</p>
<h5 id="example-12"><a href="#example-12">Example</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>chrono::{NaiveDate, NaiveDateTime};
<span class="kw">let </span>dt = NaiveDate::from_ymd_opt(<span class="number">1970</span>, <span class="number">1</span>, <span class="number">1</span>).unwrap().and_hms_nano_opt(<span class="number">0</span>, <span class="number">0</span>, <span class="number">1</span>, <span class="number">444</span>).unwrap();
<span class="macro">assert_eq!</span>(dt.timestamp_nanos(), <span class="number">1_000_000_444</span>);
<span class="kw">let </span>dt = NaiveDate::from_ymd_opt(<span class="number">2001</span>, <span class="number">9</span>, <span class="number">9</span>).unwrap().and_hms_nano_opt(<span class="number">1</span>, <span class="number">46</span>, <span class="number">40</span>, <span class="number">555</span>).unwrap();
<span class="kw">const </span>A_BILLION: i64 = <span class="number">1_000_000_000</span>;
<span class="kw">let </span>nanos = dt.timestamp_nanos();
<span class="macro">assert_eq!</span>(nanos, <span class="number">1_000_000_000_000_000_555</span>);
<span class="macro">assert_eq!</span>(
<span class="prelude-val">Some</span>(dt),
NaiveDateTime::from_timestamp_opt(nanos / A_BILLION, (nanos % A_BILLION) <span class="kw">as </span>u32)
);</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.timestamp_subsec_millis" class="method has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#505-507">source</a><h4 class="code-header">pub fn <a href="#method.timestamp_subsec_millis" class="fnname">timestamp_subsec_millis</a>(&amp;self) -&gt; u32</h4></section></summary><div class="docblock"><p>Returns the number of milliseconds since the last whole non-leap second.</p>
<p>The return value ranges from 0 to 999,
or for <a href="./struct.NaiveTime.html#leap-second-handling">leap seconds</a>, to 1,999.</p>
<h5 id="example-13"><a href="#example-13">Example</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>chrono::NaiveDate;
<span class="kw">let </span>dt = NaiveDate::from_ymd_opt(<span class="number">2016</span>, <span class="number">7</span>, <span class="number">8</span>).unwrap().and_hms_nano_opt(<span class="number">9</span>, <span class="number">10</span>, <span class="number">11</span>, <span class="number">123_456_789</span>).unwrap();
<span class="macro">assert_eq!</span>(dt.timestamp_subsec_millis(), <span class="number">123</span>);
<span class="kw">let </span>dt = NaiveDate::from_ymd_opt(<span class="number">2015</span>, <span class="number">7</span>, <span class="number">1</span>).unwrap().and_hms_nano_opt(<span class="number">8</span>, <span class="number">59</span>, <span class="number">59</span>, <span class="number">1_234_567_890</span>).unwrap();
<span class="macro">assert_eq!</span>(dt.timestamp_subsec_millis(), <span class="number">1_234</span>);</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.timestamp_subsec_micros" class="method has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#527-529">source</a><h4 class="code-header">pub fn <a href="#method.timestamp_subsec_micros" class="fnname">timestamp_subsec_micros</a>(&amp;self) -&gt; u32</h4></section></summary><div class="docblock"><p>Returns the number of microseconds since the last whole non-leap second.</p>
<p>The return value ranges from 0 to 999,999,
or for <a href="./struct.NaiveTime.html#leap-second-handling">leap seconds</a>, to 1,999,999.</p>
<h5 id="example-14"><a href="#example-14">Example</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>chrono::NaiveDate;
<span class="kw">let </span>dt = NaiveDate::from_ymd_opt(<span class="number">2016</span>, <span class="number">7</span>, <span class="number">8</span>).unwrap().and_hms_nano_opt(<span class="number">9</span>, <span class="number">10</span>, <span class="number">11</span>, <span class="number">123_456_789</span>).unwrap();
<span class="macro">assert_eq!</span>(dt.timestamp_subsec_micros(), <span class="number">123_456</span>);
<span class="kw">let </span>dt = NaiveDate::from_ymd_opt(<span class="number">2015</span>, <span class="number">7</span>, <span class="number">1</span>).unwrap().and_hms_nano_opt(<span class="number">8</span>, <span class="number">59</span>, <span class="number">59</span>, <span class="number">1_234_567_890</span>).unwrap();
<span class="macro">assert_eq!</span>(dt.timestamp_subsec_micros(), <span class="number">1_234_567</span>);</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.timestamp_subsec_nanos" class="method has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#549-551">source</a><h4 class="code-header">pub fn <a href="#method.timestamp_subsec_nanos" class="fnname">timestamp_subsec_nanos</a>(&amp;self) -&gt; u32</h4></section></summary><div class="docblock"><p>Returns the number of nanoseconds since the last whole non-leap second.</p>
<p>The return value ranges from 0 to 999,999,999,
or for <a href="./struct.NaiveTime.html#leap-second-handling">leap seconds</a>, to 1,999,999,999.</p>
<h5 id="example-15"><a href="#example-15">Example</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>chrono::NaiveDate;
<span class="kw">let </span>dt = NaiveDate::from_ymd_opt(<span class="number">2016</span>, <span class="number">7</span>, <span class="number">8</span>).unwrap().and_hms_nano_opt(<span class="number">9</span>, <span class="number">10</span>, <span class="number">11</span>, <span class="number">123_456_789</span>).unwrap();
<span class="macro">assert_eq!</span>(dt.timestamp_subsec_nanos(), <span class="number">123_456_789</span>);
<span class="kw">let </span>dt = NaiveDate::from_ymd_opt(<span class="number">2015</span>, <span class="number">7</span>, <span class="number">1</span>).unwrap().and_hms_nano_opt(<span class="number">8</span>, <span class="number">59</span>, <span class="number">59</span>, <span class="number">1_234_567_890</span>).unwrap();
<span class="macro">assert_eq!</span>(dt.timestamp_subsec_nanos(), <span class="number">1_234_567_890</span>);</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.checked_add_signed" class="method has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#619-629">source</a><h4 class="code-header">pub fn <a href="#method.checked_add_signed" class="fnname">checked_add_signed</a>(self, rhs: <a class="struct" href="../struct.Duration.html" title="struct chrono::Duration">OldDuration</a>) -&gt; Option&lt;<a class="struct" href="struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a>&gt;</h4></section></summary><div class="docblock"><p>Adds given <code>Duration</code> to the current date and time.</p>
<p>As a part of Chrono’s <a href="./struct.NaiveTime.html#leap-second-handling">leap second handling</a>,
the addition assumes that <strong>there is no leap second ever</strong>,
except when the <code>NaiveDateTime</code> itself represents a leap second
in which case the assumption becomes that <strong>there is exactly a single leap second ever</strong>.</p>
<p>Returns <code>None</code> when it will result in overflow.</p>
<h5 id="example-16"><a href="#example-16">Example</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>chrono::{Duration, NaiveDate};
<span class="kw">let </span>from_ymd = |y, m, d| NaiveDate::from_ymd_opt(y, m, d).unwrap();
<span class="kw">let </span>d = from_ymd(<span class="number">2016</span>, <span class="number">7</span>, <span class="number">8</span>);
<span class="kw">let </span>hms = |h, m, s| d.and_hms_opt(h, m, s).unwrap();
<span class="macro">assert_eq!</span>(hms(<span class="number">3</span>, <span class="number">5</span>, <span class="number">7</span>).checked_add_signed(Duration::zero()),
<span class="prelude-val">Some</span>(hms(<span class="number">3</span>, <span class="number">5</span>, <span class="number">7</span>)));
<span class="macro">assert_eq!</span>(hms(<span class="number">3</span>, <span class="number">5</span>, <span class="number">7</span>).checked_add_signed(Duration::seconds(<span class="number">1</span>)),
<span class="prelude-val">Some</span>(hms(<span class="number">3</span>, <span class="number">5</span>, <span class="number">8</span>)));
<span class="macro">assert_eq!</span>(hms(<span class="number">3</span>, <span class="number">5</span>, <span class="number">7</span>).checked_add_signed(Duration::seconds(-<span class="number">1</span>)),
<span class="prelude-val">Some</span>(hms(<span class="number">3</span>, <span class="number">5</span>, <span class="number">6</span>)));
<span class="macro">assert_eq!</span>(hms(<span class="number">3</span>, <span class="number">5</span>, <span class="number">7</span>).checked_add_signed(Duration::seconds(<span class="number">3600 </span>+ <span class="number">60</span>)),
<span class="prelude-val">Some</span>(hms(<span class="number">4</span>, <span class="number">6</span>, <span class="number">7</span>)));
<span class="macro">assert_eq!</span>(hms(<span class="number">3</span>, <span class="number">5</span>, <span class="number">7</span>).checked_add_signed(Duration::seconds(<span class="number">86_400</span>)),
<span class="prelude-val">Some</span>(from_ymd(<span class="number">2016</span>, <span class="number">7</span>, <span class="number">9</span>).and_hms_opt(<span class="number">3</span>, <span class="number">5</span>, <span class="number">7</span>).unwrap()));
<span class="kw">let </span>hmsm = |h, m, s, milli| d.and_hms_milli_opt(h, m, s, milli).unwrap();
<span class="macro">assert_eq!</span>(hmsm(<span class="number">3</span>, <span class="number">5</span>, <span class="number">7</span>, <span class="number">980</span>).checked_add_signed(Duration::milliseconds(<span class="number">450</span>)),
<span class="prelude-val">Some</span>(hmsm(<span class="number">3</span>, <span class="number">5</span>, <span class="number">8</span>, <span class="number">430</span>)));</code></pre></div>
<p>Overflow returns <code>None</code>.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="macro">assert_eq!</span>(hms(<span class="number">3</span>, <span class="number">5</span>, <span class="number">7</span>).checked_add_signed(Duration::days(<span class="number">1_000_000_000</span>)), <span class="prelude-val">None</span>);</code></pre></div>
<p>Leap seconds are handled,
but the addition assumes that it is the only leap second happened.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>leap = hmsm(<span class="number">3</span>, <span class="number">5</span>, <span class="number">59</span>, <span class="number">1_300</span>);
<span class="macro">assert_eq!</span>(leap.checked_add_signed(Duration::zero()),
<span class="prelude-val">Some</span>(hmsm(<span class="number">3</span>, <span class="number">5</span>, <span class="number">59</span>, <span class="number">1_300</span>)));
<span class="macro">assert_eq!</span>(leap.checked_add_signed(Duration::milliseconds(-<span class="number">500</span>)),
<span class="prelude-val">Some</span>(hmsm(<span class="number">3</span>, <span class="number">5</span>, <span class="number">59</span>, <span class="number">800</span>)));
<span class="macro">assert_eq!</span>(leap.checked_add_signed(Duration::milliseconds(<span class="number">500</span>)),
<span class="prelude-val">Some</span>(hmsm(<span class="number">3</span>, <span class="number">5</span>, <span class="number">59</span>, <span class="number">1_800</span>)));
<span class="macro">assert_eq!</span>(leap.checked_add_signed(Duration::milliseconds(<span class="number">800</span>)),
<span class="prelude-val">Some</span>(hmsm(<span class="number">3</span>, <span class="number">6</span>, <span class="number">0</span>, <span class="number">100</span>)));
<span class="macro">assert_eq!</span>(leap.checked_add_signed(Duration::seconds(<span class="number">10</span>)),
<span class="prelude-val">Some</span>(hmsm(<span class="number">3</span>, <span class="number">6</span>, <span class="number">9</span>, <span class="number">300</span>)));
<span class="macro">assert_eq!</span>(leap.checked_add_signed(Duration::seconds(-<span class="number">10</span>)),
<span class="prelude-val">Some</span>(hmsm(<span class="number">3</span>, <span class="number">5</span>, <span class="number">50</span>, <span class="number">300</span>)));
<span class="macro">assert_eq!</span>(leap.checked_add_signed(Duration::days(<span class="number">1</span>)),
<span class="prelude-val">Some</span>(from_ymd(<span class="number">2016</span>, <span class="number">7</span>, <span class="number">9</span>).and_hms_milli_opt(<span class="number">3</span>, <span class="number">5</span>, <span class="number">59</span>, <span class="number">300</span>).unwrap()));</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.checked_add_months" class="method has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#655-657">source</a><h4 class="code-header">pub fn <a href="#method.checked_add_months" class="fnname">checked_add_months</a>(self, rhs: <a class="struct" href="../struct.Months.html" title="struct chrono::Months">Months</a>) -&gt; Option&lt;<a class="struct" href="struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a>&gt;</h4></section></summary><div class="docblock"><p>Adds given <code>Months</code> to the current date and time.</p>
<p>Returns <code>None</code> when it will result in overflow.</p>
<p>Overflow returns <code>None</code>.</p>
<h5 id="example-17"><a href="#example-17">Example</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>chrono::{Months, NaiveDate};
<span class="macro">assert_eq!</span>(
NaiveDate::from_ymd_opt(<span class="number">2014</span>, <span class="number">1</span>, <span class="number">1</span>).unwrap().and_hms_opt(<span class="number">1</span>, <span class="number">0</span>, <span class="number">0</span>).unwrap()
.checked_add_months(Months::new(<span class="number">1</span>)),
<span class="prelude-val">Some</span>(NaiveDate::from_ymd_opt(<span class="number">2014</span>, <span class="number">2</span>, <span class="number">1</span>).unwrap().and_hms_opt(<span class="number">1</span>, <span class="number">0</span>, <span class="number">0</span>).unwrap())
);
<span class="macro">assert_eq!</span>(
NaiveDate::from_ymd_opt(<span class="number">2014</span>, <span class="number">1</span>, <span class="number">1</span>).unwrap().and_hms_opt(<span class="number">1</span>, <span class="number">0</span>, <span class="number">0</span>).unwrap()
.checked_add_months(Months::new(core::i32::MAX <span class="kw">as </span>u32 + <span class="number">1</span>)),
<span class="prelude-val">None
</span>);</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.checked_sub_signed" class="method has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#721-731">source</a><h4 class="code-header">pub fn <a href="#method.checked_sub_signed" class="fnname">checked_sub_signed</a>(self, rhs: <a class="struct" href="../struct.Duration.html" title="struct chrono::Duration">OldDuration</a>) -&gt; Option&lt;<a class="struct" href="struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a>&gt;</h4></section></summary><div class="docblock"><p>Subtracts given <code>Duration</code> from the current date and time.</p>
<p>As a part of Chrono’s <a href="./struct.NaiveTime.html#leap-second-handling">leap second handling</a>,
the subtraction assumes that <strong>there is no leap second ever</strong>,
except when the <code>NaiveDateTime</code> itself represents a leap second
in which case the assumption becomes that <strong>there is exactly a single leap second ever</strong>.</p>
<p>Returns <code>None</code> when it will result in overflow.</p>
<h5 id="example-18"><a href="#example-18">Example</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>chrono::{Duration, NaiveDate};
<span class="kw">let </span>from_ymd = |y, m, d| NaiveDate::from_ymd_opt(y, m, d).unwrap();
<span class="kw">let </span>d = from_ymd(<span class="number">2016</span>, <span class="number">7</span>, <span class="number">8</span>);
<span class="kw">let </span>hms = |h, m, s| d.and_hms_opt(h, m, s).unwrap();
<span class="macro">assert_eq!</span>(hms(<span class="number">3</span>, <span class="number">5</span>, <span class="number">7</span>).checked_sub_signed(Duration::zero()),
<span class="prelude-val">Some</span>(hms(<span class="number">3</span>, <span class="number">5</span>, <span class="number">7</span>)));
<span class="macro">assert_eq!</span>(hms(<span class="number">3</span>, <span class="number">5</span>, <span class="number">7</span>).checked_sub_signed(Duration::seconds(<span class="number">1</span>)),
<span class="prelude-val">Some</span>(hms(<span class="number">3</span>, <span class="number">5</span>, <span class="number">6</span>)));
<span class="macro">assert_eq!</span>(hms(<span class="number">3</span>, <span class="number">5</span>, <span class="number">7</span>).checked_sub_signed(Duration::seconds(-<span class="number">1</span>)),
<span class="prelude-val">Some</span>(hms(<span class="number">3</span>, <span class="number">5</span>, <span class="number">8</span>)));
<span class="macro">assert_eq!</span>(hms(<span class="number">3</span>, <span class="number">5</span>, <span class="number">7</span>).checked_sub_signed(Duration::seconds(<span class="number">3600 </span>+ <span class="number">60</span>)),
<span class="prelude-val">Some</span>(hms(<span class="number">2</span>, <span class="number">4</span>, <span class="number">7</span>)));
<span class="macro">assert_eq!</span>(hms(<span class="number">3</span>, <span class="number">5</span>, <span class="number">7</span>).checked_sub_signed(Duration::seconds(<span class="number">86_400</span>)),
<span class="prelude-val">Some</span>(from_ymd(<span class="number">2016</span>, <span class="number">7</span>, <span class="number">7</span>).and_hms_opt(<span class="number">3</span>, <span class="number">5</span>, <span class="number">7</span>).unwrap()));
<span class="kw">let </span>hmsm = |h, m, s, milli| d.and_hms_milli_opt(h, m, s, milli).unwrap();
<span class="macro">assert_eq!</span>(hmsm(<span class="number">3</span>, <span class="number">5</span>, <span class="number">7</span>, <span class="number">450</span>).checked_sub_signed(Duration::milliseconds(<span class="number">670</span>)),
<span class="prelude-val">Some</span>(hmsm(<span class="number">3</span>, <span class="number">5</span>, <span class="number">6</span>, <span class="number">780</span>)));</code></pre></div>
<p>Overflow returns <code>None</code>.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="macro">assert_eq!</span>(hms(<span class="number">3</span>, <span class="number">5</span>, <span class="number">7</span>).checked_sub_signed(Duration::days(<span class="number">1_000_000_000</span>)), <span class="prelude-val">None</span>);</code></pre></div>
<p>Leap seconds are handled,
but the subtraction assumes that it is the only leap second happened.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>leap = hmsm(<span class="number">3</span>, <span class="number">5</span>, <span class="number">59</span>, <span class="number">1_300</span>);
<span class="macro">assert_eq!</span>(leap.checked_sub_signed(Duration::zero()),
<span class="prelude-val">Some</span>(hmsm(<span class="number">3</span>, <span class="number">5</span>, <span class="number">59</span>, <span class="number">1_300</span>)));
<span class="macro">assert_eq!</span>(leap.checked_sub_signed(Duration::milliseconds(<span class="number">200</span>)),
<span class="prelude-val">Some</span>(hmsm(<span class="number">3</span>, <span class="number">5</span>, <span class="number">59</span>, <span class="number">1_100</span>)));
<span class="macro">assert_eq!</span>(leap.checked_sub_signed(Duration::milliseconds(<span class="number">500</span>)),
<span class="prelude-val">Some</span>(hmsm(<span class="number">3</span>, <span class="number">5</span>, <span class="number">59</span>, <span class="number">800</span>)));
<span class="macro">assert_eq!</span>(leap.checked_sub_signed(Duration::seconds(<span class="number">60</span>)),
<span class="prelude-val">Some</span>(hmsm(<span class="number">3</span>, <span class="number">5</span>, <span class="number">0</span>, <span class="number">300</span>)));
<span class="macro">assert_eq!</span>(leap.checked_sub_signed(Duration::days(<span class="number">1</span>)),
<span class="prelude-val">Some</span>(from_ymd(<span class="number">2016</span>, <span class="number">7</span>, <span class="number">7</span>).and_hms_milli_opt(<span class="number">3</span>, <span class="number">6</span>, <span class="number">0</span>, <span class="number">300</span>).unwrap()));</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.checked_sub_months" class="method has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#757-759">source</a><h4 class="code-header">pub fn <a href="#method.checked_sub_months" class="fnname">checked_sub_months</a>(self, rhs: <a class="struct" href="../struct.Months.html" title="struct chrono::Months">Months</a>) -&gt; Option&lt;<a class="struct" href="struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a>&gt;</h4></section></summary><div class="docblock"><p>Subtracts given <code>Months</code> from the current date and time.</p>
<p>Returns <code>None</code> when it will result in overflow.</p>
<p>Overflow returns <code>None</code>.</p>
<h5 id="example-19"><a href="#example-19">Example</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>chrono::{Months, NaiveDate};
<span class="macro">assert_eq!</span>(
NaiveDate::from_ymd_opt(<span class="number">2014</span>, <span class="number">1</span>, <span class="number">1</span>).unwrap().and_hms_opt(<span class="number">1</span>, <span class="number">0</span>, <span class="number">0</span>).unwrap()
.checked_sub_months(Months::new(<span class="number">1</span>)),
<span class="prelude-val">Some</span>(NaiveDate::from_ymd_opt(<span class="number">2013</span>, <span class="number">12</span>, <span class="number">1</span>).unwrap().and_hms_opt(<span class="number">1</span>, <span class="number">0</span>, <span class="number">0</span>).unwrap())
);
<span class="macro">assert_eq!</span>(
NaiveDate::from_ymd_opt(<span class="number">2014</span>, <span class="number">1</span>, <span class="number">1</span>).unwrap().and_hms_opt(<span class="number">1</span>, <span class="number">0</span>, <span class="number">0</span>).unwrap()
.checked_sub_months(Months::new(core::i32::MAX <span class="kw">as </span>u32 + <span class="number">1</span>)),
<span class="prelude-val">None
</span>);</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.checked_add_days" class="method has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#765-767">source</a><h4 class="code-header">pub fn <a href="#method.checked_add_days" class="fnname">checked_add_days</a>(self, days: <a class="struct" href="struct.Days.html" title="struct chrono::naive::Days">Days</a>) -&gt; Option&lt;Self&gt;</h4></section></summary><div class="docblock"><p>Add a duration in <a href="struct.Days.html" title="Days"><code>Days</code></a> to the date part of the <code>NaiveDateTime</code></p>
<p>Returns <code>None</code> if the resulting date would be out of range.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.checked_sub_days" class="method has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#773-775">source</a><h4 class="code-header">pub fn <a href="#method.checked_sub_days" class="fnname">checked_sub_days</a>(self, days: <a class="struct" href="struct.Days.html" title="struct chrono::naive::Days">Days</a>) -&gt; Option&lt;Self&gt;</h4></section></summary><div class="docblock"><p>Subtract a duration in <a href="struct.Days.html" title="Days"><code>Days</code></a> from the date part of the <code>NaiveDateTime</code></p>
<p>Returns <code>None</code> if the resulting date would be out of range.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.signed_duration_since" class="method has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#816-818">source</a><h4 class="code-header">pub fn <a href="#method.signed_duration_since" class="fnname">signed_duration_since</a>(self, rhs: <a class="struct" href="struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a>) -&gt; <a class="struct" href="../struct.Duration.html" title="struct chrono::Duration">OldDuration</a></h4></section></summary><div class="docblock"><p>Subtracts another <code>NaiveDateTime</code> from the current date and time.
This does not overflow or underflow at all.</p>
<p>As a part of Chrono’s <a href="./struct.NaiveTime.html#leap-second-handling">leap second handling</a>,
the subtraction assumes that <strong>there is no leap second ever</strong>,
except when any of the <code>NaiveDateTime</code>s themselves represents a leap second
in which case the assumption becomes that
<strong>there are exactly one (or two) leap second(s) ever</strong>.</p>
<h5 id="example-20"><a href="#example-20">Example</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>chrono::{Duration, NaiveDate};
<span class="kw">let </span>from_ymd = |y, m, d| NaiveDate::from_ymd_opt(y, m, d).unwrap();
<span class="kw">let </span>d = from_ymd(<span class="number">2016</span>, <span class="number">7</span>, <span class="number">8</span>);
<span class="macro">assert_eq!</span>(d.and_hms_opt(<span class="number">3</span>, <span class="number">5</span>, <span class="number">7</span>).unwrap().signed_duration_since(d.and_hms_opt(<span class="number">2</span>, <span class="number">4</span>, <span class="number">6</span>).unwrap()),
Duration::seconds(<span class="number">3600 </span>+ <span class="number">60 </span>+ <span class="number">1</span>));
<span class="comment">// July 8 is 190th day in the year 2016
</span><span class="kw">let </span>d0 = from_ymd(<span class="number">2016</span>, <span class="number">1</span>, <span class="number">1</span>);
<span class="macro">assert_eq!</span>(d.and_hms_milli_opt(<span class="number">0</span>, <span class="number">7</span>, <span class="number">6</span>, <span class="number">500</span>).unwrap().signed_duration_since(d0.and_hms_opt(<span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>).unwrap()),
Duration::seconds(<span class="number">189 </span>* <span class="number">86_400 </span>+ <span class="number">7 </span>* <span class="number">60 </span>+ <span class="number">6</span>) + Duration::milliseconds(<span class="number">500</span>));</code></pre></div>
<p>Leap seconds are handled, but the subtraction assumes that
there were no other leap seconds happened.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>leap = from_ymd(<span class="number">2015</span>, <span class="number">6</span>, <span class="number">30</span>).and_hms_milli_opt(<span class="number">23</span>, <span class="number">59</span>, <span class="number">59</span>, <span class="number">1_500</span>).unwrap();
<span class="macro">assert_eq!</span>(leap.signed_duration_since(from_ymd(<span class="number">2015</span>, <span class="number">6</span>, <span class="number">30</span>).and_hms_opt(<span class="number">23</span>, <span class="number">0</span>, <span class="number">0</span>).unwrap()),
Duration::seconds(<span class="number">3600</span>) + Duration::milliseconds(<span class="number">500</span>));
<span class="macro">assert_eq!</span>(from_ymd(<span class="number">2015</span>, <span class="number">7</span>, <span class="number">1</span>).and_hms_opt(<span class="number">1</span>, <span class="number">0</span>, <span class="number">0</span>).unwrap().signed_duration_since(leap),
Duration::seconds(<span class="number">3600</span>) - Duration::milliseconds(<span class="number">500</span>));</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.format_with_items" class="method has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#851-857">source</a><h4 class="code-header">pub fn <a href="#method.format_with_items" class="fnname">format_with_items</a>&lt;'a, I, B&gt;(&amp;self, items: I) -&gt; <a class="struct" href="../format/struct.DelayedFormat.html" title="struct chrono::format::DelayedFormat">DelayedFormat</a>&lt;I&gt;<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;I: Iterator&lt;Item = B&gt; + Clone,<br>&nbsp;&nbsp;&nbsp;&nbsp;B: Borrow&lt;<a class="enum" href="../format/enum.Item.html" title="enum chrono::format::Item">Item</a>&lt;'a&gt;&gt;,</span></h4></section></summary><div class="docblock"><p>Formats the combined date and time with the specified formatting items.
Otherwise it is the same as the ordinary <a href="#method.format"><code>format</code></a> method.</p>
<p>The <code>Iterator</code> of items should be <code>Clone</code>able,
since the resulting <code>DelayedFormat</code> value may be formatted multiple times.</p>
<h5 id="example-21"><a href="#example-21">Example</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>chrono::NaiveDate;
<span class="kw">use </span>chrono::format::strftime::StrftimeItems;
<span class="kw">let </span>fmt = StrftimeItems::new(<span class="string">&quot;%Y-%m-%d %H:%M:%S&quot;</span>);
<span class="kw">let </span>dt = NaiveDate::from_ymd_opt(<span class="number">2015</span>, <span class="number">9</span>, <span class="number">5</span>).unwrap().and_hms_opt(<span class="number">23</span>, <span class="number">56</span>, <span class="number">4</span>).unwrap();
<span class="macro">assert_eq!</span>(dt.format_with_items(fmt.clone()).to_string(), <span class="string">&quot;2015-09-05 23:56:04&quot;</span>);
<span class="macro">assert_eq!</span>(dt.format(<span class="string">&quot;%Y-%m-%d %H:%M:%S&quot;</span>).to_string(), <span class="string">&quot;2015-09-05 23:56:04&quot;</span>);</code></pre></div>
<p>The resulting <code>DelayedFormat</code> can be formatted directly via the <code>Display</code> trait.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="macro">assert_eq!</span>(<span class="macro">format!</span>(<span class="string">&quot;{}&quot;</span>, dt.format_with_items(fmt)), <span class="string">&quot;2015-09-05 23:56:04&quot;</span>);</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.format" class="method has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#895-897">source</a><h4 class="code-header">pub fn <a href="#method.format" class="fnname">format</a>&lt;'a&gt;(&amp;self, fmt: &amp;'a str) -&gt; <a class="struct" href="../format/struct.DelayedFormat.html" title="struct chrono::format::DelayedFormat">DelayedFormat</a>&lt;<a class="struct" href="../format/strftime/struct.StrftimeItems.html" title="struct chrono::format::strftime::StrftimeItems">StrftimeItems</a>&lt;'a&gt;&gt;</h4></section></summary><div class="docblock"><p>Formats the combined date and time with the specified format string.
See the <a href="../format/strftime/index.html"><code>format::strftime</code> module</a>
on the supported escape sequences.</p>
<p>This returns a <code>DelayedFormat</code>,
which gets converted to a string only when actual formatting happens.
You may use the <code>to_string</code> method to get a <code>String</code>,
or just feed it into <code>print!</code> and other formatting macros.
(In this way it avoids the redundant memory allocation.)</p>
<p>A wrong format string does <em>not</em> issue an error immediately.
Rather, converting or formatting the <code>DelayedFormat</code> fails.
You are recommended to immediately use <code>DelayedFormat</code> for this reason.</p>
<h5 id="example-22"><a href="#example-22">Example</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>chrono::NaiveDate;
<span class="kw">let </span>dt = NaiveDate::from_ymd_opt(<span class="number">2015</span>, <span class="number">9</span>, <span class="number">5</span>).unwrap().and_hms_opt(<span class="number">23</span>, <span class="number">56</span>, <span class="number">4</span>).unwrap();
<span class="macro">assert_eq!</span>(dt.format(<span class="string">&quot;%Y-%m-%d %H:%M:%S&quot;</span>).to_string(), <span class="string">&quot;2015-09-05 23:56:04&quot;</span>);
<span class="macro">assert_eq!</span>(dt.format(<span class="string">&quot;around %l %p on %b %-d&quot;</span>).to_string(), <span class="string">&quot;around 11 PM on Sep 5&quot;</span>);</code></pre></div>
<p>The resulting <code>DelayedFormat</code> can be formatted directly via the <code>Display</code> trait.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="macro">assert_eq!</span>(<span class="macro">format!</span>(<span class="string">&quot;{}&quot;</span>, dt.format(<span class="string">&quot;%Y-%m-%d %H:%M:%S&quot;</span>)), <span class="string">&quot;2015-09-05 23:56:04&quot;</span>);
<span class="macro">assert_eq!</span>(<span class="macro">format!</span>(<span class="string">&quot;{}&quot;</span>, dt.format(<span class="string">&quot;around %l %p on %b %-d&quot;</span>)), <span class="string">&quot;around 11 PM on Sep 5&quot;</span>);</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.and_local_timezone" class="method has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#920-922">source</a><h4 class="code-header">pub fn <a href="#method.and_local_timezone" class="fnname">and_local_timezone</a>&lt;Tz:&nbsp;<a class="trait" href="../offset/trait.TimeZone.html" title="trait chrono::offset::TimeZone">TimeZone</a>&gt;(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;self,<br>&nbsp;&nbsp;&nbsp;&nbsp;tz: Tz<br>) -&gt; <a class="enum" href="../offset/enum.LocalResult.html" title="enum chrono::offset::LocalResult">LocalResult</a>&lt;<a class="struct" href="../struct.DateTime.html" title="struct chrono::DateTime">DateTime</a>&lt;Tz&gt;&gt;</h4></section></summary><div class="docblock"><p>Converts the <code>NaiveDateTime</code> into the timezone-aware <code>DateTime&lt;Tz&gt;</code>
with the provided timezone, if possible.</p>
<p>This can fail in cases where the local time represented by the <code>NaiveDateTime</code>
is not a valid local timestamp in the target timezone due to an offset transition
for example if the target timezone had a change from +00:00 to +01:00
occuring at 2015-09-05 22:59:59, then a local time of 2015-09-05 23:56:04
could never occur. Similarly, if the offset transitioned in the opposite direction
then there would be two local times of 2015-09-05 23:56:04, one at +00:00 and one
at +01:00.</p>
<h5 id="example-23"><a href="#example-23">Example</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>chrono::{NaiveDate, FixedOffset};
<span class="kw">let </span>hour = <span class="number">3600</span>;
<span class="kw">let </span>tz = FixedOffset::east_opt(<span class="number">5 </span>* hour).unwrap();
<span class="kw">let </span>dt = NaiveDate::from_ymd_opt(<span class="number">2015</span>, <span class="number">9</span>, <span class="number">5</span>).unwrap().and_hms_opt(<span class="number">23</span>, <span class="number">56</span>, <span class="number">4</span>).unwrap().and_local_timezone(tz).unwrap();
<span class="macro">assert_eq!</span>(dt.timezone(), tz);</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.and_utc" class="method has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#934-936">source</a><h4 class="code-header">pub fn <a href="#method.and_utc" class="fnname">and_utc</a>(&amp;self) -&gt; <a class="struct" href="../struct.DateTime.html" title="struct chrono::DateTime">DateTime</a>&lt;<a class="struct" href="../offset/struct.Utc.html" title="struct chrono::offset::Utc">Utc</a>&gt;</h4></section></summary><div class="docblock"><p>Converts the <code>NaiveDateTime</code> into the timezone-aware <code>DateTime&lt;Utc&gt;</code>.</p>
<h5 id="example-24"><a href="#example-24">Example</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>chrono::{NaiveDate, Utc};
<span class="kw">let </span>dt = NaiveDate::from_ymd_opt(<span class="number">2023</span>, <span class="number">1</span>, <span class="number">30</span>).unwrap().and_hms_opt(<span class="number">19</span>, <span class="number">32</span>, <span class="number">33</span>).unwrap().and_utc();
<span class="macro">assert_eq!</span>(dt.timezone(), Utc);</code></pre></div>
</div></details><details class="rustdoc-toggle" open><summary><section id="associatedconstant.MIN" class="associatedconstant has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#939">source</a><h4 class="code-header">pub const <a href="#associatedconstant.MIN" class="constant">MIN</a>: Self = _</h4></section></summary><div class="docblock"><p>The minimum possible <code>NaiveDateTime</code>.</p>
</div></details><details class="rustdoc-toggle" open><summary><section id="associatedconstant.MAX" class="associatedconstant has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#941">source</a><h4 class="code-header">pub const <a href="#associatedconstant.MAX" class="constant">MAX</a>: Self = _</h4></section></summary><div class="docblock"><p>The maximum possible <code>NaiveDateTime</code>.</p>
</div></details></div></details></div><h2 id="trait-implementations" class="small-section-header">Trait Implementations<a href="#trait-implementations" class="anchor"></a></h2><div id="trait-implementations-list"><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-Add%3CDays%3E-for-NaiveDateTime" class="impl has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#1673-1679">source</a><a href="#impl-Add%3CDays%3E-for-NaiveDateTime" class="anchor"></a><h3 class="code-header">impl Add&lt;<a class="struct" href="struct.Days.html" title="struct chrono::naive::Days">Days</a>&gt; for <a class="struct" href="struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle" open><summary><section id="associatedtype.Output-5" class="associatedtype trait-impl has-srclink"><a href="#associatedtype.Output-5" class="anchor"></a><h4 class="code-header">type <a class="associatedtype">Output</a> = <a class="struct" href="struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a></h4></section></summary><div class='docblock'>The resulting type after applying the <code>+</code> operator.</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.add-2" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#1676-1678">source</a><a href="#method.add-2" class="anchor"></a><h4 class="code-header">fn <a class="fnname">add</a>(self, days: <a class="struct" href="struct.Days.html" title="struct chrono::naive::Days">Days</a>) -&gt; Self::Output</h4></section></summary><div class='docblock'>Performs the <code>+</code> operation. <a>Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-Add%3CDuration%3E-for-NaiveDateTime" class="impl has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#1468-1475">source</a><a href="#impl-Add%3CDuration%3E-for-NaiveDateTime" class="anchor"></a><h3 class="code-header">impl Add&lt;<a class="struct" href="../struct.Duration.html" title="struct chrono::Duration">Duration</a>&gt; for <a class="struct" href="struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a></h3></section></summary><div class="docblock"><p>An addition of <code>Duration</code> to <code>NaiveDateTime</code> yields another <code>NaiveDateTime</code>.</p>
<p>As a part of Chrono’s <a href="struct.NaiveTime.html#leap-second-handling">leap second handling</a>, the addition assumes that <strong>there is no leap
second ever</strong>, except when the <code>NaiveDateTime</code> itself represents a leap second in which case
the assumption becomes that <strong>there is exactly a single leap second ever</strong>.</p>
<p>Panics on underflow or overflow. Use <a href="struct.NaiveDateTime.html#method.checked_add_signed" title="NaiveDateTime::checked_add_signed"><code>NaiveDateTime::checked_add_signed</code></a>
to detect that.</p>
<h4 id="example-48"><a href="#example-48">Example</a></h4>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>chrono::{Duration, NaiveDate};
<span class="kw">let </span>from_ymd = |y, m, d| NaiveDate::from_ymd_opt(y, m, d).unwrap();
<span class="kw">let </span>d = from_ymd(<span class="number">2016</span>, <span class="number">7</span>, <span class="number">8</span>);
<span class="kw">let </span>hms = |h, m, s| d.and_hms_opt(h, m, s).unwrap();
<span class="macro">assert_eq!</span>(hms(<span class="number">3</span>, <span class="number">5</span>, <span class="number">7</span>) + Duration::zero(), hms(<span class="number">3</span>, <span class="number">5</span>, <span class="number">7</span>));
<span class="macro">assert_eq!</span>(hms(<span class="number">3</span>, <span class="number">5</span>, <span class="number">7</span>) + Duration::seconds(<span class="number">1</span>), hms(<span class="number">3</span>, <span class="number">5</span>, <span class="number">8</span>));
<span class="macro">assert_eq!</span>(hms(<span class="number">3</span>, <span class="number">5</span>, <span class="number">7</span>) + Duration::seconds(-<span class="number">1</span>), hms(<span class="number">3</span>, <span class="number">5</span>, <span class="number">6</span>));
<span class="macro">assert_eq!</span>(hms(<span class="number">3</span>, <span class="number">5</span>, <span class="number">7</span>) + Duration::seconds(<span class="number">3600 </span>+ <span class="number">60</span>), hms(<span class="number">4</span>, <span class="number">6</span>, <span class="number">7</span>));
<span class="macro">assert_eq!</span>(hms(<span class="number">3</span>, <span class="number">5</span>, <span class="number">7</span>) + Duration::seconds(<span class="number">86_400</span>),
from_ymd(<span class="number">2016</span>, <span class="number">7</span>, <span class="number">9</span>).and_hms_opt(<span class="number">3</span>, <span class="number">5</span>, <span class="number">7</span>).unwrap());
<span class="macro">assert_eq!</span>(hms(<span class="number">3</span>, <span class="number">5</span>, <span class="number">7</span>) + Duration::days(<span class="number">365</span>),
from_ymd(<span class="number">2017</span>, <span class="number">7</span>, <span class="number">8</span>).and_hms_opt(<span class="number">3</span>, <span class="number">5</span>, <span class="number">7</span>).unwrap());
<span class="kw">let </span>hmsm = |h, m, s, milli| d.and_hms_milli_opt(h, m, s, milli).unwrap();
<span class="macro">assert_eq!</span>(hmsm(<span class="number">3</span>, <span class="number">5</span>, <span class="number">7</span>, <span class="number">980</span>) + Duration::milliseconds(<span class="number">450</span>), hmsm(<span class="number">3</span>, <span class="number">5</span>, <span class="number">8</span>, <span class="number">430</span>));</code></pre></div>
<p>Leap seconds are handled,
but the addition assumes that it is the only leap second happened.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>leap = hmsm(<span class="number">3</span>, <span class="number">5</span>, <span class="number">59</span>, <span class="number">1_300</span>);
<span class="macro">assert_eq!</span>(leap + Duration::zero(), hmsm(<span class="number">3</span>, <span class="number">5</span>, <span class="number">59</span>, <span class="number">1_300</span>));
<span class="macro">assert_eq!</span>(leap + Duration::milliseconds(-<span class="number">500</span>), hmsm(<span class="number">3</span>, <span class="number">5</span>, <span class="number">59</span>, <span class="number">800</span>));
<span class="macro">assert_eq!</span>(leap + Duration::milliseconds(<span class="number">500</span>), hmsm(<span class="number">3</span>, <span class="number">5</span>, <span class="number">59</span>, <span class="number">1_800</span>));
<span class="macro">assert_eq!</span>(leap + Duration::milliseconds(<span class="number">800</span>), hmsm(<span class="number">3</span>, <span class="number">6</span>, <span class="number">0</span>, <span class="number">100</span>));
<span class="macro">assert_eq!</span>(leap + Duration::seconds(<span class="number">10</span>), hmsm(<span class="number">3</span>, <span class="number">6</span>, <span class="number">9</span>, <span class="number">300</span>));
<span class="macro">assert_eq!</span>(leap + Duration::seconds(-<span class="number">10</span>), hmsm(<span class="number">3</span>, <span class="number">5</span>, <span class="number">50</span>, <span class="number">300</span>));
<span class="macro">assert_eq!</span>(leap + Duration::days(<span class="number">1</span>),
from_ymd(<span class="number">2016</span>, <span class="number">7</span>, <span class="number">9</span>).and_hms_milli_opt(<span class="number">3</span>, <span class="number">5</span>, <span class="number">59</span>, <span class="number">300</span>).unwrap());</code></pre></div>
</div><div class="impl-items"><details class="rustdoc-toggle" open><summary><section id="associatedtype.Output" class="associatedtype trait-impl has-srclink"><a href="#associatedtype.Output" class="anchor"></a><h4 class="code-header">type <a class="associatedtype">Output</a> = <a class="struct" href="struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a></h4></section></summary><div class='docblock'>The resulting type after applying the <code>+</code> operator.</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.add" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#1472-1474">source</a><a href="#method.add" class="anchor"></a><h4 class="code-header">fn <a class="fnname">add</a>(self, rhs: <a class="struct" href="../struct.Duration.html" title="struct chrono::Duration">OldDuration</a>) -&gt; <a class="struct" href="struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a></h4></section></summary><div class='docblock'>Performs the <code>+</code> operation. <a>Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-Add%3CFixedOffset%3E-for-NaiveDateTime" class="impl has-srclink"><a class="srclink rightside" href="../../src/chrono/offset/fixed.rs.html#209-216">source</a><a href="#impl-Add%3CFixedOffset%3E-for-NaiveDateTime" class="anchor"></a><h3 class="code-header">impl Add&lt;<a class="struct" href="../offset/struct.FixedOffset.html" title="struct chrono::offset::FixedOffset">FixedOffset</a>&gt; for <a class="struct" href="struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle" open><summary><section id="associatedtype.Output-7" class="associatedtype trait-impl has-srclink"><a href="#associatedtype.Output-7" class="anchor"></a><h4 class="code-header">type <a class="associatedtype">Output</a> = <a class="struct" href="struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a></h4></section></summary><div class='docblock'>The resulting type after applying the <code>+</code> operator.</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.add-3" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/chrono/offset/fixed.rs.html#213-215">source</a><a href="#method.add-3" class="anchor"></a><h4 class="code-header">fn <a class="fnname">add</a>(self, rhs: <a class="struct" href="../offset/struct.FixedOffset.html" title="struct chrono::offset::FixedOffset">FixedOffset</a>) -&gt; <a class="struct" href="struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a></h4></section></summary><div class='docblock'>Performs the <code>+</code> operation. <a>Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-Add%3CMonths%3E-for-NaiveDateTime" class="impl has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#1484-1526">source</a><a href="#impl-Add%3CMonths%3E-for-NaiveDateTime" class="anchor"></a><h3 class="code-header">impl Add&lt;<a class="struct" href="../struct.Months.html" title="struct chrono::Months">Months</a>&gt; for <a class="struct" href="struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.add-1" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#1523-1525">source</a><a href="#method.add-1" class="anchor"></a><h4 class="code-header">fn <a class="fnname">add</a>(self, rhs: <a class="struct" href="../struct.Months.html" title="struct chrono::Months">Months</a>) -&gt; Self::Output</h4></section></summary><div class="docblock"><p>An addition of months to <code>NaiveDateTime</code> clamped to valid days in resulting month.</p>
<h5 id="panics-1"><a href="#panics-1">Panics</a></h5>
<p>Panics if the resulting date would be out of range.</p>
<h5 id="example-49"><a href="#example-49">Example</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>chrono::{Months, NaiveDate};
<span class="macro">assert_eq!</span>(
NaiveDate::from_ymd_opt(<span class="number">2014</span>, <span class="number">1</span>, <span class="number">1</span>).unwrap().and_hms_opt(<span class="number">1</span>, <span class="number">0</span>, <span class="number">0</span>).unwrap() + Months::new(<span class="number">1</span>),
NaiveDate::from_ymd_opt(<span class="number">2014</span>, <span class="number">2</span>, <span class="number">1</span>).unwrap().and_hms_opt(<span class="number">1</span>, <span class="number">0</span>, <span class="number">0</span>).unwrap()
);
<span class="macro">assert_eq!</span>(
NaiveDate::from_ymd_opt(<span class="number">2014</span>, <span class="number">1</span>, <span class="number">1</span>).unwrap().and_hms_opt(<span class="number">0</span>, <span class="number">2</span>, <span class="number">0</span>).unwrap() + Months::new(<span class="number">11</span>),
NaiveDate::from_ymd_opt(<span class="number">2014</span>, <span class="number">12</span>, <span class="number">1</span>).unwrap().and_hms_opt(<span class="number">0</span>, <span class="number">2</span>, <span class="number">0</span>).unwrap()
);
<span class="macro">assert_eq!</span>(
NaiveDate::from_ymd_opt(<span class="number">2014</span>, <span class="number">1</span>, <span class="number">1</span>).unwrap().and_hms_opt(<span class="number">0</span>, <span class="number">0</span>, <span class="number">3</span>).unwrap() + Months::new(<span class="number">12</span>),
NaiveDate::from_ymd_opt(<span class="number">2015</span>, <span class="number">1</span>, <span class="number">1</span>).unwrap().and_hms_opt(<span class="number">0</span>, <span class="number">0</span>, <span class="number">3</span>).unwrap()
);
<span class="macro">assert_eq!</span>(
NaiveDate::from_ymd_opt(<span class="number">2014</span>, <span class="number">1</span>, <span class="number">1</span>).unwrap().and_hms_opt(<span class="number">0</span>, <span class="number">0</span>, <span class="number">4</span>).unwrap() + Months::new(<span class="number">13</span>),
NaiveDate::from_ymd_opt(<span class="number">2015</span>, <span class="number">2</span>, <span class="number">1</span>).unwrap().and_hms_opt(<span class="number">0</span>, <span class="number">0</span>, <span class="number">4</span>).unwrap()
);
<span class="macro">assert_eq!</span>(
NaiveDate::from_ymd_opt(<span class="number">2014</span>, <span class="number">1</span>, <span class="number">31</span>).unwrap().and_hms_opt(<span class="number">0</span>, <span class="number">5</span>, <span class="number">0</span>).unwrap() + Months::new(<span class="number">1</span>),
NaiveDate::from_ymd_opt(<span class="number">2014</span>, <span class="number">2</span>, <span class="number">28</span>).unwrap().and_hms_opt(<span class="number">0</span>, <span class="number">5</span>, <span class="number">0</span>).unwrap()
);
<span class="macro">assert_eq!</span>(
NaiveDate::from_ymd_opt(<span class="number">2020</span>, <span class="number">1</span>, <span class="number">31</span>).unwrap().and_hms_opt(<span class="number">6</span>, <span class="number">0</span>, <span class="number">0</span>).unwrap() + Months::new(<span class="number">1</span>),
NaiveDate::from_ymd_opt(<span class="number">2020</span>, <span class="number">2</span>, <span class="number">29</span>).unwrap().and_hms_opt(<span class="number">6</span>, <span class="number">0</span>, <span class="number">0</span>).unwrap()
);</code></pre></div>
</div></details><details class="rustdoc-toggle" open><summary><section id="associatedtype.Output-1" class="associatedtype trait-impl has-srclink"><a href="#associatedtype.Output-1" class="anchor"></a><h4 class="code-header">type <a class="associatedtype">Output</a> = <a class="struct" href="struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a></h4></section></summary><div class='docblock'>The resulting type after applying the <code>+</code> operator.</div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-AddAssign%3CDuration%3E-for-NaiveDateTime" class="impl has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#1477-1482">source</a><a href="#impl-AddAssign%3CDuration%3E-for-NaiveDateTime" class="anchor"></a><h3 class="code-header">impl AddAssign&lt;<a class="struct" href="../struct.Duration.html" title="struct chrono::Duration">Duration</a>&gt; for <a class="struct" href="struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.add_assign" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#1479-1481">source</a><a href="#method.add_assign" class="anchor"></a><h4 class="code-header">fn <a class="fnname">add_assign</a>(&amp;mut self, rhs: <a class="struct" href="../struct.Duration.html" title="struct chrono::Duration">OldDuration</a>)</h4></section></summary><div class='docblock'>Performs the <code>+=</code> operation. <a>Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-Clone-for-NaiveDateTime" class="impl has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#74">source</a><a href="#impl-Clone-for-NaiveDateTime" class="anchor"></a><h3 class="code-header">impl Clone for <a class="struct" href="struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.clone" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#74">source</a><a href="#method.clone" class="anchor"></a><h4 class="code-header">fn <a class="fnname">clone</a>(&amp;self) -&gt; <a class="struct" href="struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a></h4></section></summary><div class='docblock'>Returns a copy of the value. <a>Read more</a></div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.clone_from" class="method trait-impl has-srclink"><span class="since rightside" title="Stable since Rust version 1.0.0">1.0.0</span><a href="#method.clone_from" class="anchor"></a><h4 class="code-header">const fn <a class="fnname">clone_from</a>(&amp;mut self, source: &amp;Self)</h4></section></summary><div class='docblock'>Performs copy-assignment from <code>source</code>. <a>Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-Datelike-for-NaiveDateTime" class="impl has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#944-1253">source</a><a href="#impl-Datelike-for-NaiveDateTime" class="anchor"></a><h3 class="code-header">impl <a class="trait" href="../trait.Datelike.html" title="trait chrono::Datelike">Datelike</a> for <a class="struct" href="struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.year" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#958-960">source</a><a href="#method.year" class="anchor"></a><h4 class="code-header">fn <a href="../trait.Datelike.html#tymethod.year" class="fnname">year</a>(&amp;self) -&gt; i32</h4></section></summary><div class="docblock"><p>Returns the year number in the <a href="./struct.NaiveDate.html#calendar-date">calendar date</a>.</p>
<p>See also the <a href="struct.NaiveDate.html#method.year" title="NaiveDate::year"><code>NaiveDate::year</code></a> method.</p>
<h5 id="example-25"><a href="#example-25">Example</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>chrono::{NaiveDate, NaiveDateTime, Datelike};
<span class="kw">let </span>dt: NaiveDateTime = NaiveDate::from_ymd_opt(<span class="number">2015</span>, <span class="number">9</span>, <span class="number">25</span>).unwrap().and_hms_opt(<span class="number">12</span>, <span class="number">34</span>, <span class="number">56</span>).unwrap();
<span class="macro">assert_eq!</span>(dt.year(), <span class="number">2015</span>);</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.month" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#977-979">source</a><a href="#method.month" class="anchor"></a><h4 class="code-header">fn <a href="../trait.Datelike.html#tymethod.month" class="fnname">month</a>(&amp;self) -&gt; u32</h4></section></summary><div class="docblock"><p>Returns the month number starting from 1.</p>
<p>The return value ranges from 1 to 12.</p>
<p>See also the <a href="./struct.NaiveDate.html#method.month"><code>NaiveDate::month</code></a> method.</p>
<h5 id="example-26"><a href="#example-26">Example</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>chrono::{NaiveDate, NaiveDateTime, Datelike};
<span class="kw">let </span>dt: NaiveDateTime = NaiveDate::from_ymd_opt(<span class="number">2015</span>, <span class="number">9</span>, <span class="number">25</span>).unwrap().and_hms_opt(<span class="number">12</span>, <span class="number">34</span>, <span class="number">56</span>).unwrap();
<span class="macro">assert_eq!</span>(dt.month(), <span class="number">9</span>);</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.month0" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#996-998">source</a><a href="#method.month0" class="anchor"></a><h4 class="code-header">fn <a href="../trait.Datelike.html#tymethod.month0" class="fnname">month0</a>(&amp;self) -&gt; u32</h4></section></summary><div class="docblock"><p>Returns the month number starting from 0.</p>
<p>The return value ranges from 0 to 11.</p>
<p>See also the <a href="./struct.NaiveDate.html#method.month0"><code>NaiveDate::month0</code></a> method.</p>
<h5 id="example-27"><a href="#example-27">Example</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>chrono::{NaiveDate, NaiveDateTime, Datelike};
<span class="kw">let </span>dt: NaiveDateTime = NaiveDate::from_ymd_opt(<span class="number">2015</span>, <span class="number">9</span>, <span class="number">25</span>).unwrap().and_hms_opt(<span class="number">12</span>, <span class="number">34</span>, <span class="number">56</span>).unwrap();
<span class="macro">assert_eq!</span>(dt.month0(), <span class="number">8</span>);</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.day" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#1015-1017">source</a><a href="#method.day" class="anchor"></a><h4 class="code-header">fn <a href="../trait.Datelike.html#tymethod.day" class="fnname">day</a>(&amp;self) -&gt; u32</h4></section></summary><div class="docblock"><p>Returns the day of month starting from 1.</p>
<p>The return value ranges from 1 to 31. (The last day of month differs by months.)</p>
<p>See also the <a href="./struct.NaiveDate.html#method.day"><code>NaiveDate::day</code></a> method.</p>
<h5 id="example-28"><a href="#example-28">Example</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>chrono::{NaiveDate, NaiveDateTime, Datelike};
<span class="kw">let </span>dt: NaiveDateTime = NaiveDate::from_ymd_opt(<span class="number">2015</span>, <span class="number">9</span>, <span class="number">25</span>).unwrap().and_hms_opt(<span class="number">12</span>, <span class="number">34</span>, <span class="number">56</span>).unwrap();
<span class="macro">assert_eq!</span>(dt.day(), <span class="number">25</span>);</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.day0" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#1034-1036">source</a><a href="#method.day0" class="anchor"></a><h4 class="code-header">fn <a href="../trait.Datelike.html#tymethod.day0" class="fnname">day0</a>(&amp;self) -&gt; u32</h4></section></summary><div class="docblock"><p>Returns the day of month starting from 0.</p>
<p>The return value ranges from 0 to 30. (The last day of month differs by months.)</p>
<p>See also the <a href="./struct.NaiveDate.html#method.day0"><code>NaiveDate::day0</code></a> method.</p>
<h5 id="example-29"><a href="#example-29">Example</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>chrono::{NaiveDate, NaiveDateTime, Datelike};
<span class="kw">let </span>dt: NaiveDateTime = NaiveDate::from_ymd_opt(<span class="number">2015</span>, <span class="number">9</span>, <span class="number">25</span>).unwrap().and_hms_opt(<span class="number">12</span>, <span class="number">34</span>, <span class="number">56</span>).unwrap();
<span class="macro">assert_eq!</span>(dt.day0(), <span class="number">24</span>);</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.ordinal" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#1053-1055">source</a><a href="#method.ordinal" class="anchor"></a><h4 class="code-header">fn <a href="../trait.Datelike.html#tymethod.ordinal" class="fnname">ordinal</a>(&amp;self) -&gt; u32</h4></section></summary><div class="docblock"><p>Returns the day of year starting from 1.</p>
<p>The return value ranges from 1 to 366. (The last day of year differs by years.)</p>
<p>See also the <a href="./struct.NaiveDate.html#method.ordinal"><code>NaiveDate::ordinal</code></a> method.</p>
<h5 id="example-30"><a href="#example-30">Example</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>chrono::{NaiveDate, NaiveDateTime, Datelike};
<span class="kw">let </span>dt: NaiveDateTime = NaiveDate::from_ymd_opt(<span class="number">2015</span>, <span class="number">9</span>, <span class="number">25</span>).unwrap().and_hms_opt(<span class="number">12</span>, <span class="number">34</span>, <span class="number">56</span>).unwrap();
<span class="macro">assert_eq!</span>(dt.ordinal(), <span class="number">268</span>);</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.ordinal0" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#1072-1074">source</a><a href="#method.ordinal0" class="anchor"></a><h4 class="code-header">fn <a href="../trait.Datelike.html#tymethod.ordinal0" class="fnname">ordinal0</a>(&amp;self) -&gt; u32</h4></section></summary><div class="docblock"><p>Returns the day of year starting from 0.</p>
<p>The return value ranges from 0 to 365. (The last day of year differs by years.)</p>
<p>See also the <a href="./struct.NaiveDate.html#method.ordinal0"><code>NaiveDate::ordinal0</code></a> method.</p>
<h5 id="example-31"><a href="#example-31">Example</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>chrono::{NaiveDate, NaiveDateTime, Datelike};
<span class="kw">let </span>dt: NaiveDateTime = NaiveDate::from_ymd_opt(<span class="number">2015</span>, <span class="number">9</span>, <span class="number">25</span>).unwrap().and_hms_opt(<span class="number">12</span>, <span class="number">34</span>, <span class="number">56</span>).unwrap();
<span class="macro">assert_eq!</span>(dt.ordinal0(), <span class="number">267</span>);</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.weekday" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#1089-1091">source</a><a href="#method.weekday" class="anchor"></a><h4 class="code-header">fn <a href="../trait.Datelike.html#tymethod.weekday" class="fnname">weekday</a>(&amp;self) -&gt; <a class="enum" href="../enum.Weekday.html" title="enum chrono::Weekday">Weekday</a></h4></section></summary><div class="docblock"><p>Returns the day of week.</p>
<p>See also the <a href="./struct.NaiveDate.html#method.weekday"><code>NaiveDate::weekday</code></a> method.</p>
<h5 id="example-32"><a href="#example-32">Example</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>chrono::{NaiveDate, NaiveDateTime, Datelike, Weekday};
<span class="kw">let </span>dt: NaiveDateTime = NaiveDate::from_ymd_opt(<span class="number">2015</span>, <span class="number">9</span>, <span class="number">25</span>).unwrap().and_hms_opt(<span class="number">12</span>, <span class="number">34</span>, <span class="number">56</span>).unwrap();
<span class="macro">assert_eq!</span>(dt.weekday(), Weekday::Fri);</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.with_year" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#1114-1116">source</a><a href="#method.with_year" class="anchor"></a><h4 class="code-header">fn <a href="../trait.Datelike.html#tymethod.with_year" class="fnname">with_year</a>(&amp;self, year: i32) -&gt; Option&lt;<a class="struct" href="struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a>&gt;</h4></section></summary><div class="docblock"><p>Makes a new <code>NaiveDateTime</code> with the year number changed.</p>
<p>Returns <code>None</code> when the resulting <code>NaiveDateTime</code> would be invalid.</p>
<p>See also the <a href="struct.NaiveDate.html#method.with_year" title="NaiveDate::with_year"><code>NaiveDate::with_year</code></a> method.</p>
<h5 id="example-33"><a href="#example-33">Example</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>chrono::{NaiveDate, NaiveDateTime, Datelike};
<span class="kw">let </span>dt: NaiveDateTime = NaiveDate::from_ymd_opt(<span class="number">2015</span>, <span class="number">9</span>, <span class="number">25</span>).unwrap().and_hms_opt(<span class="number">12</span>, <span class="number">34</span>, <span class="number">56</span>).unwrap();
<span class="macro">assert_eq!</span>(dt.with_year(<span class="number">2016</span>), <span class="prelude-val">Some</span>(NaiveDate::from_ymd_opt(<span class="number">2016</span>, <span class="number">9</span>, <span class="number">25</span>).unwrap().and_hms_opt(<span class="number">12</span>, <span class="number">34</span>, <span class="number">56</span>).unwrap()));
<span class="macro">assert_eq!</span>(dt.with_year(-<span class="number">308</span>), <span class="prelude-val">Some</span>(NaiveDate::from_ymd_opt(-<span class="number">308</span>, <span class="number">9</span>, <span class="number">25</span>).unwrap().and_hms_opt(<span class="number">12</span>, <span class="number">34</span>, <span class="number">56</span>).unwrap()));</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.with_month" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#1135-1137">source</a><a href="#method.with_month" class="anchor"></a><h4 class="code-header">fn <a href="../trait.Datelike.html#tymethod.with_month" class="fnname">with_month</a>(&amp;self, month: u32) -&gt; Option&lt;<a class="struct" href="struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a>&gt;</h4></section></summary><div class="docblock"><p>Makes a new <code>NaiveDateTime</code> with the month number (starting from 1) changed.</p>
<p>Returns <code>None</code> when the resulting <code>NaiveDateTime</code> would be invalid.</p>
<p>See also the <a href="struct.NaiveDate.html#method.with_month" title="NaiveDate::with_month"><code>NaiveDate::with_month</code></a> method.</p>
<h5 id="example-34"><a href="#example-34">Example</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>chrono::{NaiveDate, NaiveDateTime, Datelike};
<span class="kw">let </span>dt: NaiveDateTime = NaiveDate::from_ymd_opt(<span class="number">2015</span>, <span class="number">9</span>, <span class="number">30</span>).unwrap().and_hms_opt(<span class="number">12</span>, <span class="number">34</span>, <span class="number">56</span>).unwrap();
<span class="macro">assert_eq!</span>(dt.with_month(<span class="number">10</span>), <span class="prelude-val">Some</span>(NaiveDate::from_ymd_opt(<span class="number">2015</span>, <span class="number">10</span>, <span class="number">30</span>).unwrap().and_hms_opt(<span class="number">12</span>, <span class="number">34</span>, <span class="number">56</span>).unwrap()));
<span class="macro">assert_eq!</span>(dt.with_month(<span class="number">13</span>), <span class="prelude-val">None</span>); <span class="comment">// no month 13
</span><span class="macro">assert_eq!</span>(dt.with_month(<span class="number">2</span>), <span class="prelude-val">None</span>); <span class="comment">// no February 30</span></code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.with_month0" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#1156-1158">source</a><a href="#method.with_month0" class="anchor"></a><h4 class="code-header">fn <a href="../trait.Datelike.html#tymethod.with_month0" class="fnname">with_month0</a>(&amp;self, month0: u32) -&gt; Option&lt;<a class="struct" href="struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a>&gt;</h4></section></summary><div class="docblock"><p>Makes a new <code>NaiveDateTime</code> with the month number (starting from 0) changed.</p>
<p>Returns <code>None</code> when the resulting <code>NaiveDateTime</code> would be invalid.</p>
<p>See also the <a href="struct.NaiveDate.html#method.with_month0" title="NaiveDate::with_month0"><code>NaiveDate::with_month0</code></a> method.</p>
<h5 id="example-35"><a href="#example-35">Example</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>chrono::{NaiveDate, NaiveDateTime, Datelike};
<span class="kw">let </span>dt: NaiveDateTime = NaiveDate::from_ymd_opt(<span class="number">2015</span>, <span class="number">9</span>, <span class="number">30</span>).unwrap().and_hms_opt(<span class="number">12</span>, <span class="number">34</span>, <span class="number">56</span>).unwrap();
<span class="macro">assert_eq!</span>(dt.with_month0(<span class="number">9</span>), <span class="prelude-val">Some</span>(NaiveDate::from_ymd_opt(<span class="number">2015</span>, <span class="number">10</span>, <span class="number">30</span>).unwrap().and_hms_opt(<span class="number">12</span>, <span class="number">34</span>, <span class="number">56</span>).unwrap()));
<span class="macro">assert_eq!</span>(dt.with_month0(<span class="number">12</span>), <span class="prelude-val">None</span>); <span class="comment">// no month 13
</span><span class="macro">assert_eq!</span>(dt.with_month0(<span class="number">1</span>), <span class="prelude-val">None</span>); <span class="comment">// no February 30</span></code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.with_day" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#1176-1178">source</a><a href="#method.with_day" class="anchor"></a><h4 class="code-header">fn <a href="../trait.Datelike.html#tymethod.with_day" class="fnname">with_day</a>(&amp;self, day: u32) -&gt; Option&lt;<a class="struct" href="struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a>&gt;</h4></section></summary><div class="docblock"><p>Makes a new <code>NaiveDateTime</code> with the day of month (starting from 1) changed.</p>
<p>Returns <code>None</code> when the resulting <code>NaiveDateTime</code> would be invalid.</p>
<p>See also the <a href="struct.NaiveDate.html#method.with_day" title="NaiveDate::with_day"><code>NaiveDate::with_day</code></a> method.</p>
<h5 id="example-36"><a href="#example-36">Example</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>chrono::{NaiveDate, NaiveDateTime, Datelike};
<span class="kw">let </span>dt: NaiveDateTime = NaiveDate::from_ymd_opt(<span class="number">2015</span>, <span class="number">9</span>, <span class="number">8</span>).unwrap().and_hms_opt(<span class="number">12</span>, <span class="number">34</span>, <span class="number">56</span>).unwrap();
<span class="macro">assert_eq!</span>(dt.with_day(<span class="number">30</span>), <span class="prelude-val">Some</span>(NaiveDate::from_ymd_opt(<span class="number">2015</span>, <span class="number">9</span>, <span class="number">30</span>).unwrap().and_hms_opt(<span class="number">12</span>, <span class="number">34</span>, <span class="number">56</span>).unwrap()));
<span class="macro">assert_eq!</span>(dt.with_day(<span class="number">31</span>), <span class="prelude-val">None</span>); <span class="comment">// no September 31</span></code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.with_day0" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#1196-1198">source</a><a href="#method.with_day0" class="anchor"></a><h4 class="code-header">fn <a href="../trait.Datelike.html#tymethod.with_day0" class="fnname">with_day0</a>(&amp;self, day0: u32) -&gt; Option&lt;<a class="struct" href="struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a>&gt;</h4></section></summary><div class="docblock"><p>Makes a new <code>NaiveDateTime</code> with the day of month (starting from 0) changed.</p>
<p>Returns <code>None</code> when the resulting <code>NaiveDateTime</code> would be invalid.</p>
<p>See also the <a href="struct.NaiveDate.html#method.with_day0" title="NaiveDate::with_day0"><code>NaiveDate::with_day0</code></a> method.</p>
<h5 id="example-37"><a href="#example-37">Example</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>chrono::{NaiveDate, NaiveDateTime, Datelike};
<span class="kw">let </span>dt: NaiveDateTime = NaiveDate::from_ymd_opt(<span class="number">2015</span>, <span class="number">9</span>, <span class="number">8</span>).unwrap().and_hms_opt(<span class="number">12</span>, <span class="number">34</span>, <span class="number">56</span>).unwrap();
<span class="macro">assert_eq!</span>(dt.with_day0(<span class="number">29</span>), <span class="prelude-val">Some</span>(NaiveDate::from_ymd_opt(<span class="number">2015</span>, <span class="number">9</span>, <span class="number">30</span>).unwrap().and_hms_opt(<span class="number">12</span>, <span class="number">34</span>, <span class="number">56</span>).unwrap()));
<span class="macro">assert_eq!</span>(dt.with_day0(<span class="number">30</span>), <span class="prelude-val">None</span>); <span class="comment">// no September 31</span></code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.with_ordinal" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#1223-1225">source</a><a href="#method.with_ordinal" class="anchor"></a><h4 class="code-header">fn <a href="../trait.Datelike.html#tymethod.with_ordinal" class="fnname">with_ordinal</a>(&amp;self, ordinal: u32) -&gt; Option&lt;<a class="struct" href="struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a>&gt;</h4></section></summary><div class="docblock"><p>Makes a new <code>NaiveDateTime</code> with the day of year (starting from 1) changed.</p>
<p>Returns <code>None</code> when the resulting <code>NaiveDateTime</code> would be invalid.</p>
<p>See also the <a href="struct.NaiveDate.html#method.with_ordinal" title="NaiveDate::with_ordinal"><code>NaiveDate::with_ordinal</code></a> method.</p>
<h5 id="example-38"><a href="#example-38">Example</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>chrono::{NaiveDate, NaiveDateTime, Datelike};
<span class="kw">let </span>dt: NaiveDateTime = NaiveDate::from_ymd_opt(<span class="number">2015</span>, <span class="number">9</span>, <span class="number">8</span>).unwrap().and_hms_opt(<span class="number">12</span>, <span class="number">34</span>, <span class="number">56</span>).unwrap();
<span class="macro">assert_eq!</span>(dt.with_ordinal(<span class="number">60</span>),
<span class="prelude-val">Some</span>(NaiveDate::from_ymd_opt(<span class="number">2015</span>, <span class="number">3</span>, <span class="number">1</span>).unwrap().and_hms_opt(<span class="number">12</span>, <span class="number">34</span>, <span class="number">56</span>).unwrap()));
<span class="macro">assert_eq!</span>(dt.with_ordinal(<span class="number">366</span>), <span class="prelude-val">None</span>); <span class="comment">// 2015 had only 365 days
</span><span class="kw">let </span>dt: NaiveDateTime = NaiveDate::from_ymd_opt(<span class="number">2016</span>, <span class="number">9</span>, <span class="number">8</span>).unwrap().and_hms_opt(<span class="number">12</span>, <span class="number">34</span>, <span class="number">56</span>).unwrap();
<span class="macro">assert_eq!</span>(dt.with_ordinal(<span class="number">60</span>),
<span class="prelude-val">Some</span>(NaiveDate::from_ymd_opt(<span class="number">2016</span>, <span class="number">2</span>, <span class="number">29</span>).unwrap().and_hms_opt(<span class="number">12</span>, <span class="number">34</span>, <span class="number">56</span>).unwrap()));
<span class="macro">assert_eq!</span>(dt.with_ordinal(<span class="number">366</span>),
<span class="prelude-val">Some</span>(NaiveDate::from_ymd_opt(<span class="number">2016</span>, <span class="number">12</span>, <span class="number">31</span>).unwrap().and_hms_opt(<span class="number">12</span>, <span class="number">34</span>, <span class="number">56</span>).unwrap()));</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.with_ordinal0" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#1250-1252">source</a><a href="#method.with_ordinal0" class="anchor"></a><h4 class="code-header">fn <a href="../trait.Datelike.html#tymethod.with_ordinal0" class="fnname">with_ordinal0</a>(&amp;self, ordinal0: u32) -&gt; Option&lt;<a class="struct" href="struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a>&gt;</h4></section></summary><div class="docblock"><p>Makes a new <code>NaiveDateTime</code> with the day of year (starting from 0) changed.</p>
<p>Returns <code>None</code> when the resulting <code>NaiveDateTime</code> would be invalid.</p>
<p>See also the <a href="struct.NaiveDate.html#method.with_ordinal0" title="NaiveDate::with_ordinal0"><code>NaiveDate::with_ordinal0</code></a> method.</p>
<h5 id="example-39"><a href="#example-39">Example</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>chrono::{NaiveDate, NaiveDateTime, Datelike};
<span class="kw">let </span>dt: NaiveDateTime = NaiveDate::from_ymd_opt(<span class="number">2015</span>, <span class="number">9</span>, <span class="number">8</span>).unwrap().and_hms_opt(<span class="number">12</span>, <span class="number">34</span>, <span class="number">56</span>).unwrap();
<span class="macro">assert_eq!</span>(dt.with_ordinal0(<span class="number">59</span>),
<span class="prelude-val">Some</span>(NaiveDate::from_ymd_opt(<span class="number">2015</span>, <span class="number">3</span>, <span class="number">1</span>).unwrap().and_hms_opt(<span class="number">12</span>, <span class="number">34</span>, <span class="number">56</span>).unwrap()));
<span class="macro">assert_eq!</span>(dt.with_ordinal0(<span class="number">365</span>), <span class="prelude-val">None</span>); <span class="comment">// 2015 had only 365 days
</span><span class="kw">let </span>dt: NaiveDateTime = NaiveDate::from_ymd_opt(<span class="number">2016</span>, <span class="number">9</span>, <span class="number">8</span>).unwrap().and_hms_opt(<span class="number">12</span>, <span class="number">34</span>, <span class="number">56</span>).unwrap();
<span class="macro">assert_eq!</span>(dt.with_ordinal0(<span class="number">59</span>),
<span class="prelude-val">Some</span>(NaiveDate::from_ymd_opt(<span class="number">2016</span>, <span class="number">2</span>, <span class="number">29</span>).unwrap().and_hms_opt(<span class="number">12</span>, <span class="number">34</span>, <span class="number">56</span>).unwrap()));
<span class="macro">assert_eq!</span>(dt.with_ordinal0(<span class="number">365</span>),
<span class="prelude-val">Some</span>(NaiveDate::from_ymd_opt(<span class="number">2016</span>, <span class="number">12</span>, <span class="number">31</span>).unwrap().and_hms_opt(<span class="number">12</span>, <span class="number">34</span>, <span class="number">56</span>).unwrap()));</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.iso_week" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#1094-1096">source</a><a href="#method.iso_week" class="anchor"></a><h4 class="code-header">fn <a href="../trait.Datelike.html#tymethod.iso_week" class="fnname">iso_week</a>(&amp;self) -&gt; <a class="struct" href="struct.IsoWeek.html" title="struct chrono::naive::IsoWeek">IsoWeek</a></h4></section></summary><div class='docblock'>Returns the ISO week.</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.year_ce" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/chrono/traits.rs.html#11-18">source</a><a href="#method.year_ce" class="anchor"></a><h4 class="code-header">fn <a href="../trait.Datelike.html#method.year_ce" class="fnname">year_ce</a>(&amp;self) -&gt; (bool, u32)</h4></section></summary><div class='docblock'>Returns the absolute year number starting from 1 with a boolean flag,
which is false when the year predates the epoch (BCE/BC) and true otherwise (CE/AD). <a href="../trait.Datelike.html#method.year_ce">Read more</a></div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.num_days_from_ce" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/chrono/traits.rs.html#103-118">source</a><a href="#method.num_days_from_ce" class="anchor"></a><h4 class="code-header">fn <a href="../trait.Datelike.html#method.num_days_from_ce" class="fnname">num_days_from_ce</a>(&amp;self) -&gt; i32</h4></section></summary><div class='docblock'>Counts the days in the proleptic Gregorian calendar, with January 1, Year 1 (CE) as day 1. <a href="../trait.Datelike.html#method.num_days_from_ce">Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-Debug-for-NaiveDateTime" class="impl has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#1716-1722">source</a><a href="#impl-Debug-for-NaiveDateTime" class="anchor"></a><h3 class="code-header">impl Debug for <a class="struct" href="struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a></h3></section></summary><div class="docblock"><p>The <code>Debug</code> output of the naive date and time <code>dt</code> is the same as
<a href="../format/strftime/index.html"><code>dt.format(&quot;%Y-%m-%dT%H:%M:%S%.f&quot;)</code></a>.</p>
<p>The string printed can be readily parsed via the <code>parse</code> method on <code>str</code>.</p>
<p>It should be noted that, for leap seconds not on the minute boundary,
it may print a representation not distinguishable from non-leap seconds.
This doesn’t matter in practice, since such leap seconds never happened.
(By the time of the first leap second on 1972-06-30,
every time zone offset around the world has standardized to the 5-minute alignment.)</p>
<h4 id="example-53"><a href="#example-53">Example</a></h4>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>chrono::NaiveDate;
<span class="kw">let </span>dt = NaiveDate::from_ymd_opt(<span class="number">2016</span>, <span class="number">11</span>, <span class="number">15</span>).unwrap().and_hms_opt(<span class="number">7</span>, <span class="number">39</span>, <span class="number">24</span>).unwrap();
<span class="macro">assert_eq!</span>(<span class="macro">format!</span>(<span class="string">&quot;{:?}&quot;</span>, dt), <span class="string">&quot;2016-11-15T07:39:24&quot;</span>);</code></pre></div>
<p>Leap seconds may also be used.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>dt = NaiveDate::from_ymd_opt(<span class="number">2015</span>, <span class="number">6</span>, <span class="number">30</span>).unwrap().and_hms_milli_opt(<span class="number">23</span>, <span class="number">59</span>, <span class="number">59</span>, <span class="number">1_500</span>).unwrap();
<span class="macro">assert_eq!</span>(<span class="macro">format!</span>(<span class="string">&quot;{:?}&quot;</span>, dt), <span class="string">&quot;2015-06-30T23:59:60.500&quot;</span>);</code></pre></div>
</div><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.fmt" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#1717-1721">source</a><a href="#method.fmt" class="anchor"></a><h4 class="code-header">fn <a class="fnname">fmt</a>(&amp;self, f: &amp;mut Formatter&lt;'_&gt;) -&gt; Result</h4></section></summary><div class='docblock'>Formats the value using the given formatter. <a>Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-Default-for-NaiveDateTime" class="impl has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#1815-1819">source</a><a href="#impl-Default-for-NaiveDateTime" class="anchor"></a><h3 class="code-header">impl Default for <a class="struct" href="struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a></h3></section></summary><div class="docblock"><p>The default value for a NaiveDateTime is one with epoch 0
that is, 1st of January 1970 at 00:00:00.</p>
<h4 id="example-56"><a href="#example-56">Example</a></h4>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>chrono::NaiveDateTime;
<span class="kw">let </span>default_date = NaiveDateTime::default();
<span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>(default_date), NaiveDateTime::from_timestamp_opt(<span class="number">0</span>, <span class="number">0</span>));</code></pre></div>
</div><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.default" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#1816-1818">source</a><a href="#method.default" class="anchor"></a><h4 class="code-header">fn <a class="fnname">default</a>() -&gt; Self</h4></section></summary><div class='docblock'>Returns the “default value” for a type. <a>Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-Display-for-NaiveDateTime" class="impl has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#1749-1755">source</a><a href="#impl-Display-for-NaiveDateTime" class="anchor"></a><h3 class="code-header">impl Display for <a class="struct" href="struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a></h3></section></summary><div class="docblock"><p>The <code>Display</code> output of the naive date and time <code>dt</code> is the same as
<a href="../format/strftime/index.html"><code>dt.format(&quot;%Y-%m-%d %H:%M:%S%.f&quot;)</code></a>.</p>
<p>It should be noted that, for leap seconds not on the minute boundary,
it may print a representation not distinguishable from non-leap seconds.
This doesn’t matter in practice, since such leap seconds never happened.
(By the time of the first leap second on 1972-06-30,
every time zone offset around the world has standardized to the 5-minute alignment.)</p>
<h4 id="example-54"><a href="#example-54">Example</a></h4>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>chrono::NaiveDate;
<span class="kw">let </span>dt = NaiveDate::from_ymd_opt(<span class="number">2016</span>, <span class="number">11</span>, <span class="number">15</span>).unwrap().and_hms_opt(<span class="number">7</span>, <span class="number">39</span>, <span class="number">24</span>).unwrap();
<span class="macro">assert_eq!</span>(<span class="macro">format!</span>(<span class="string">&quot;{}&quot;</span>, dt), <span class="string">&quot;2016-11-15 07:39:24&quot;</span>);</code></pre></div>
<p>Leap seconds may also be used.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>dt = NaiveDate::from_ymd_opt(<span class="number">2015</span>, <span class="number">6</span>, <span class="number">30</span>).unwrap().and_hms_milli_opt(<span class="number">23</span>, <span class="number">59</span>, <span class="number">59</span>, <span class="number">1_500</span>).unwrap();
<span class="macro">assert_eq!</span>(<span class="macro">format!</span>(<span class="string">&quot;{}&quot;</span>, dt), <span class="string">&quot;2015-06-30 23:59:60.500&quot;</span>);</code></pre></div>
</div><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.fmt-1" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#1750-1754">source</a><a href="#method.fmt-1" class="anchor"></a><h4 class="code-header">fn <a class="fnname">fmt</a>(&amp;self, f: &amp;mut Formatter&lt;'_&gt;) -&gt; Result</h4></section></summary><div class='docblock'>Formats the value using the given formatter. <a>Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-DurationRound-for-NaiveDateTime" class="impl has-srclink"><a class="srclink rightside" href="../../src/chrono/round.rs.html#160-170">source</a><a href="#impl-DurationRound-for-NaiveDateTime" class="anchor"></a><h3 class="code-header">impl <a class="trait" href="../trait.DurationRound.html" title="trait chrono::DurationRound">DurationRound</a> for <a class="struct" href="struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle" open><summary><section id="associatedtype.Err-1" class="associatedtype trait-impl has-srclink"><a href="#associatedtype.Err-1" class="anchor"></a><h4 class="code-header">type <a href="../trait.DurationRound.html#associatedtype.Err" class="associatedtype">Err</a> = <a class="enum" href="../enum.RoundingError.html" title="enum chrono::RoundingError">RoundingError</a></h4></section></summary><div class='docblock'>Error that can occur in rounding or truncating</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.duration_round" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/chrono/round.rs.html#163-165">source</a><a href="#method.duration_round" class="anchor"></a><h4 class="code-header">fn <a href="../trait.DurationRound.html#tymethod.duration_round" class="fnname">duration_round</a>(self, duration: <a class="struct" href="../struct.Duration.html" title="struct chrono::Duration">Duration</a>) -&gt; Result&lt;Self, Self::<a class="associatedtype" href="../trait.DurationRound.html#associatedtype.Err" title="type chrono::DurationRound::Err">Err</a>&gt;</h4></section></summary><div class='docblock'>Return a copy rounded by Duration. <a href="../trait.DurationRound.html#tymethod.duration_round">Read more</a></div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.duration_trunc" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/chrono/round.rs.html#167-169">source</a><a href="#method.duration_trunc" class="anchor"></a><h4 class="code-header">fn <a href="../trait.DurationRound.html#tymethod.duration_trunc" class="fnname">duration_trunc</a>(self, duration: <a class="struct" href="../struct.Duration.html" title="struct chrono::Duration">Duration</a>) -&gt; Result&lt;Self, Self::<a class="associatedtype" href="../trait.DurationRound.html#associatedtype.Err" title="type chrono::DurationRound::Err">Err</a>&gt;</h4></section></summary><div class='docblock'>Return a copy truncated by Duration. <a href="../trait.DurationRound.html#tymethod.duration_trunc">Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-From%3CNaiveDateTime%3E-for-NaiveDate" class="impl has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/date.rs.html#1886-1890">source</a><a href="#impl-From%3CNaiveDateTime%3E-for-NaiveDate" class="anchor"></a><h3 class="code-header">impl From&lt;<a class="struct" href="struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a>&gt; for <a class="struct" href="struct.NaiveDate.html" title="struct chrono::naive::NaiveDate">NaiveDate</a></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.from" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/date.rs.html#1887-1889">source</a><a href="#method.from" class="anchor"></a><h4 class="code-header">fn <a class="fnname">from</a>(naive_datetime: <a class="struct" href="struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a>) -&gt; Self</h4></section></summary><div class='docblock'>Converts to this type from the input type.</div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-FromStr-for-NaiveDateTime" class="impl has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#1773-1802">source</a><a href="#impl-FromStr-for-NaiveDateTime" class="anchor"></a><h3 class="code-header">impl FromStr for <a class="struct" href="struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a></h3></section></summary><div class="docblock"><p>Parsing a <code>str</code> into a <code>NaiveDateTime</code> uses the same format,
<a href="../format/strftime/index.html"><code>%Y-%m-%dT%H:%M:%S%.f</code></a>, as in <code>Debug</code>.</p>
<h4 id="example-55"><a href="#example-55">Example</a></h4>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>chrono::{NaiveDateTime, NaiveDate};
<span class="kw">let </span>dt = NaiveDate::from_ymd_opt(<span class="number">2015</span>, <span class="number">9</span>, <span class="number">18</span>).unwrap().and_hms_opt(<span class="number">23</span>, <span class="number">56</span>, <span class="number">4</span>).unwrap();
<span class="macro">assert_eq!</span>(<span class="string">&quot;2015-09-18T23:56:04&quot;</span>.parse::&lt;NaiveDateTime&gt;(), <span class="prelude-val">Ok</span>(dt));
<span class="kw">let </span>dt = NaiveDate::from_ymd_opt(<span class="number">12345</span>, <span class="number">6</span>, <span class="number">7</span>).unwrap().and_hms_milli_opt(<span class="number">7</span>, <span class="number">59</span>, <span class="number">59</span>, <span class="number">1_500</span>).unwrap(); <span class="comment">// leap second
</span><span class="macro">assert_eq!</span>(<span class="string">&quot;+12345-6-7T7:59:60.5&quot;</span>.parse::&lt;NaiveDateTime&gt;(), <span class="prelude-val">Ok</span>(dt));
<span class="macro">assert!</span>(<span class="string">&quot;foo&quot;</span>.parse::&lt;NaiveDateTime&gt;().is_err());</code></pre></div>
</div><div class="impl-items"><details class="rustdoc-toggle" open><summary><section id="associatedtype.Err" class="associatedtype trait-impl has-srclink"><a href="#associatedtype.Err" class="anchor"></a><h4 class="code-header">type <a class="associatedtype">Err</a> = <a class="struct" href="../format/struct.ParseError.html" title="struct chrono::format::ParseError">ParseError</a></h4></section></summary><div class='docblock'>The associated error which can be returned from parsing.</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.from_str" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#1776-1801">source</a><a href="#method.from_str" class="anchor"></a><h4 class="code-header">fn <a class="fnname">from_str</a>(s: &amp;str) -&gt; <a class="type" href="../format/type.ParseResult.html" title="type chrono::format::ParseResult">ParseResult</a>&lt;<a class="struct" href="struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a>&gt;</h4></section></summary><div class='docblock'>Parses a string <code>s</code> to return a value of this type. <a>Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-Hash-for-NaiveDateTime" class="impl has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#74">source</a><a href="#impl-Hash-for-NaiveDateTime" class="anchor"></a><h3 class="code-header">impl Hash for <a class="struct" href="struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.hash" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#74">source</a><a href="#method.hash" class="anchor"></a><h4 class="code-header">fn <a class="fnname">hash</a>&lt;__H:&nbsp;Hasher&gt;(&amp;self, state: &amp;mut __H)</h4></section></summary><div class='docblock'>Feeds this value into the given [<code>Hasher</code>]. <a>Read more</a></div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.hash_slice" class="method trait-impl has-srclink"><span class="since rightside" title="Stable since Rust version 1.3.0">1.3.0</span><a href="#method.hash_slice" class="anchor"></a><h4 class="code-header">fn <a class="fnname">hash_slice</a>&lt;H&gt;(data: &amp;[Self], state: &amp;mut H)<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;H: Hasher,</span></h4></section></summary><div class='docblock'>Feeds a slice of this type into the given [<code>Hasher</code>]. <a>Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-Ord-for-NaiveDateTime" class="impl has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#74">source</a><a href="#impl-Ord-for-NaiveDateTime" class="anchor"></a><h3 class="code-header">impl Ord for <a class="struct" href="struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.cmp" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#74">source</a><a href="#method.cmp" class="anchor"></a><h4 class="code-header">fn <a class="fnname">cmp</a>(&amp;self, other: &amp;<a class="struct" href="struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a>) -&gt; Ordering</h4></section></summary><div class='docblock'>This method returns an [<code>Ordering</code>] between <code>self</code> and <code>other</code>. <a>Read more</a></div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.max" class="method trait-impl has-srclink"><span class="since rightside" title="Stable since Rust version 1.21.0">1.21.0</span><a href="#method.max" class="anchor"></a><h4 class="code-header">const fn <a class="fnname">max</a>(self, other: Self) -&gt; Self</h4></section></summary><div class='docblock'>Compares and returns the maximum of two values. <a>Read more</a></div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.min" class="method trait-impl has-srclink"><span class="since rightside" title="Stable since Rust version 1.21.0">1.21.0</span><a href="#method.min" class="anchor"></a><h4 class="code-header">const fn <a class="fnname">min</a>(self, other: Self) -&gt; Self</h4></section></summary><div class='docblock'>Compares and returns the minimum of two values. <a>Read more</a></div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.clamp" class="method trait-impl has-srclink"><span class="since rightside" title="Stable since Rust version 1.50.0">1.50.0</span><a href="#method.clamp" class="anchor"></a><h4 class="code-header">const fn <a class="fnname">clamp</a>(self, min: Self, max: Self) -&gt; Self<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;Self: PartialOrd&lt;Self&gt;,</span></h4></section></summary><div class='docblock'>Restrict a value to a certain interval. <a>Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-PartialEq%3CNaiveDateTime%3E-for-NaiveDateTime" class="impl has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#74">source</a><a href="#impl-PartialEq%3CNaiveDateTime%3E-for-NaiveDateTime" class="anchor"></a><h3 class="code-header">impl PartialEq&lt;<a class="struct" href="struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a>&gt; for <a class="struct" href="struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.eq" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#74">source</a><a href="#method.eq" class="anchor"></a><h4 class="code-header">fn <a class="fnname">eq</a>(&amp;self, other: &amp;<a class="struct" href="struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a>) -&gt; bool</h4></section></summary><div class='docblock'>This method tests for <code>self</code> and <code>other</code> values to be equal, and is used
by <code>==</code>. <a>Read more</a></div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.ne" class="method trait-impl has-srclink"><span class="since rightside" title="Stable since Rust version 1.0.0">1.0.0</span><a href="#method.ne" class="anchor"></a><h4 class="code-header">const fn <a class="fnname">ne</a>(&amp;self, other: &amp;Rhs) -&gt; bool</h4></section></summary><div class='docblock'>This method tests for <code>!=</code>. The default implementation is almost always
sufficient, and should not be overridden without very good reason. <a>Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-PartialOrd%3CNaiveDateTime%3E-for-NaiveDateTime" class="impl has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#74">source</a><a href="#impl-PartialOrd%3CNaiveDateTime%3E-for-NaiveDateTime" class="anchor"></a><h3 class="code-header">impl PartialOrd&lt;<a class="struct" href="struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a>&gt; for <a class="struct" href="struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.partial_cmp" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#74">source</a><a href="#method.partial_cmp" class="anchor"></a><h4 class="code-header">fn <a class="fnname">partial_cmp</a>(&amp;self, other: &amp;<a class="struct" href="struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a>) -&gt; Option&lt;Ordering&gt;</h4></section></summary><div class='docblock'>This method returns an ordering between <code>self</code> and <code>other</code> values if one exists. <a>Read more</a></div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.lt" class="method trait-impl has-srclink"><span class="since rightside" title="Stable since Rust version 1.0.0">1.0.0</span><a href="#method.lt" class="anchor"></a><h4 class="code-header">const fn <a class="fnname">lt</a>(&amp;self, other: &amp;Rhs) -&gt; bool</h4></section></summary><div class='docblock'>This method tests less than (for <code>self</code> and <code>other</code>) and is used by the <code>&lt;</code> operator. <a>Read more</a></div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.le" class="method trait-impl has-srclink"><span class="since rightside" title="Stable since Rust version 1.0.0">1.0.0</span><a href="#method.le" class="anchor"></a><h4 class="code-header">const fn <a class="fnname">le</a>(&amp;self, other: &amp;Rhs) -&gt; bool</h4></section></summary><div class='docblock'>This method tests less than or equal to (for <code>self</code> and <code>other</code>) and is used by the <code>&lt;=</code>
operator. <a>Read more</a></div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.gt" class="method trait-impl has-srclink"><span class="since rightside" title="Stable since Rust version 1.0.0">1.0.0</span><a href="#method.gt" class="anchor"></a><h4 class="code-header">const fn <a class="fnname">gt</a>(&amp;self, other: &amp;Rhs) -&gt; bool</h4></section></summary><div class='docblock'>This method tests greater than (for <code>self</code> and <code>other</code>) and is used by the <code>&gt;</code> operator. <a>Read more</a></div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.ge" class="method trait-impl has-srclink"><span class="since rightside" title="Stable since Rust version 1.0.0">1.0.0</span><a href="#method.ge" class="anchor"></a><h4 class="code-header">const fn <a class="fnname">ge</a>(&amp;self, other: &amp;Rhs) -&gt; bool</h4></section></summary><div class='docblock'>This method tests greater than or equal to (for <code>self</code> and <code>other</code>) and is used by the <code>&gt;=</code>
operator. <a>Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-Sub%3CDays%3E-for-NaiveDateTime" class="impl has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#1681-1687">source</a><a href="#impl-Sub%3CDays%3E-for-NaiveDateTime" class="anchor"></a><h3 class="code-header">impl Sub&lt;<a class="struct" href="struct.Days.html" title="struct chrono::naive::Days">Days</a>&gt; for <a class="struct" href="struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle" open><summary><section id="associatedtype.Output-6" class="associatedtype trait-impl has-srclink"><a href="#associatedtype.Output-6" class="anchor"></a><h4 class="code-header">type <a class="associatedtype">Output</a> = <a class="struct" href="struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a></h4></section></summary><div class='docblock'>The resulting type after applying the <code>-</code> operator.</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.sub-3" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#1684-1686">source</a><a href="#method.sub-3" class="anchor"></a><h4 class="code-header">fn <a class="fnname">sub</a>(self, days: <a class="struct" href="struct.Days.html" title="struct chrono::naive::Days">Days</a>) -&gt; Self::Output</h4></section></summary><div class='docblock'>Performs the <code>-</code> operation. <a>Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-Sub%3CDuration%3E-for-NaiveDateTime" class="impl has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#1577-1584">source</a><a href="#impl-Sub%3CDuration%3E-for-NaiveDateTime" class="anchor"></a><h3 class="code-header">impl Sub&lt;<a class="struct" href="../struct.Duration.html" title="struct chrono::Duration">Duration</a>&gt; for <a class="struct" href="struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a></h3></section></summary><div class="docblock"><p>A subtraction of <code>Duration</code> from <code>NaiveDateTime</code> yields another <code>NaiveDateTime</code>.
It is the same as the addition with a negated <code>Duration</code>.</p>
<p>As a part of Chrono’s <a href="struct.NaiveTime.html#leap-second-handling">leap second handling</a> the subtraction assumes that <strong>there is no leap
second ever</strong>, except when the <code>NaiveDateTime</code> itself represents a leap second in which case
the assumption becomes that <strong>there is exactly a single leap second ever</strong>.</p>
<p>Panics on underflow or overflow. Use <a href="struct.NaiveDateTime.html#method.checked_sub_signed" title="NaiveDateTime::checked_sub_signed"><code>NaiveDateTime::checked_sub_signed</code></a>
to detect that.</p>
<h4 id="example-50"><a href="#example-50">Example</a></h4>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>chrono::{Duration, NaiveDate};
<span class="kw">let </span>from_ymd = |y, m, d| NaiveDate::from_ymd_opt(y, m, d).unwrap();
<span class="kw">let </span>d = from_ymd(<span class="number">2016</span>, <span class="number">7</span>, <span class="number">8</span>);
<span class="kw">let </span>hms = |h, m, s| d.and_hms_opt(h, m, s).unwrap();
<span class="macro">assert_eq!</span>(hms(<span class="number">3</span>, <span class="number">5</span>, <span class="number">7</span>) - Duration::zero(), hms(<span class="number">3</span>, <span class="number">5</span>, <span class="number">7</span>));
<span class="macro">assert_eq!</span>(hms(<span class="number">3</span>, <span class="number">5</span>, <span class="number">7</span>) - Duration::seconds(<span class="number">1</span>), hms(<span class="number">3</span>, <span class="number">5</span>, <span class="number">6</span>));
<span class="macro">assert_eq!</span>(hms(<span class="number">3</span>, <span class="number">5</span>, <span class="number">7</span>) - Duration::seconds(-<span class="number">1</span>), hms(<span class="number">3</span>, <span class="number">5</span>, <span class="number">8</span>));
<span class="macro">assert_eq!</span>(hms(<span class="number">3</span>, <span class="number">5</span>, <span class="number">7</span>) - Duration::seconds(<span class="number">3600 </span>+ <span class="number">60</span>), hms(<span class="number">2</span>, <span class="number">4</span>, <span class="number">7</span>));
<span class="macro">assert_eq!</span>(hms(<span class="number">3</span>, <span class="number">5</span>, <span class="number">7</span>) - Duration::seconds(<span class="number">86_400</span>),
from_ymd(<span class="number">2016</span>, <span class="number">7</span>, <span class="number">7</span>).and_hms_opt(<span class="number">3</span>, <span class="number">5</span>, <span class="number">7</span>).unwrap());
<span class="macro">assert_eq!</span>(hms(<span class="number">3</span>, <span class="number">5</span>, <span class="number">7</span>) - Duration::days(<span class="number">365</span>),
from_ymd(<span class="number">2015</span>, <span class="number">7</span>, <span class="number">9</span>).and_hms_opt(<span class="number">3</span>, <span class="number">5</span>, <span class="number">7</span>).unwrap());
<span class="kw">let </span>hmsm = |h, m, s, milli| d.and_hms_milli_opt(h, m, s, milli).unwrap();
<span class="macro">assert_eq!</span>(hmsm(<span class="number">3</span>, <span class="number">5</span>, <span class="number">7</span>, <span class="number">450</span>) - Duration::milliseconds(<span class="number">670</span>), hmsm(<span class="number">3</span>, <span class="number">5</span>, <span class="number">6</span>, <span class="number">780</span>));</code></pre></div>
<p>Leap seconds are handled,
but the subtraction assumes that it is the only leap second happened.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>leap = hmsm(<span class="number">3</span>, <span class="number">5</span>, <span class="number">59</span>, <span class="number">1_300</span>);
<span class="macro">assert_eq!</span>(leap - Duration::zero(), hmsm(<span class="number">3</span>, <span class="number">5</span>, <span class="number">59</span>, <span class="number">1_300</span>));
<span class="macro">assert_eq!</span>(leap - Duration::milliseconds(<span class="number">200</span>), hmsm(<span class="number">3</span>, <span class="number">5</span>, <span class="number">59</span>, <span class="number">1_100</span>));
<span class="macro">assert_eq!</span>(leap - Duration::milliseconds(<span class="number">500</span>), hmsm(<span class="number">3</span>, <span class="number">5</span>, <span class="number">59</span>, <span class="number">800</span>));
<span class="macro">assert_eq!</span>(leap - Duration::seconds(<span class="number">60</span>), hmsm(<span class="number">3</span>, <span class="number">5</span>, <span class="number">0</span>, <span class="number">300</span>));
<span class="macro">assert_eq!</span>(leap - Duration::days(<span class="number">1</span>),
from_ymd(<span class="number">2016</span>, <span class="number">7</span>, <span class="number">7</span>).and_hms_milli_opt(<span class="number">3</span>, <span class="number">6</span>, <span class="number">0</span>, <span class="number">300</span>).unwrap());</code></pre></div>
</div><div class="impl-items"><details class="rustdoc-toggle" open><summary><section id="associatedtype.Output-2" class="associatedtype trait-impl has-srclink"><a href="#associatedtype.Output-2" class="anchor"></a><h4 class="code-header">type <a class="associatedtype">Output</a> = <a class="struct" href="struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a></h4></section></summary><div class='docblock'>The resulting type after applying the <code>-</code> operator.</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.sub" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#1581-1583">source</a><a href="#method.sub" class="anchor"></a><h4 class="code-header">fn <a class="fnname">sub</a>(self, rhs: <a class="struct" href="../struct.Duration.html" title="struct chrono::Duration">OldDuration</a>) -&gt; <a class="struct" href="struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a></h4></section></summary><div class='docblock'>Performs the <code>-</code> operation. <a>Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-Sub%3CFixedOffset%3E-for-NaiveDateTime" class="impl has-srclink"><a class="srclink rightside" href="../../src/chrono/offset/fixed.rs.html#218-225">source</a><a href="#impl-Sub%3CFixedOffset%3E-for-NaiveDateTime" class="anchor"></a><h3 class="code-header">impl Sub&lt;<a class="struct" href="../offset/struct.FixedOffset.html" title="struct chrono::offset::FixedOffset">FixedOffset</a>&gt; for <a class="struct" href="struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle" open><summary><section id="associatedtype.Output-8" class="associatedtype trait-impl has-srclink"><a href="#associatedtype.Output-8" class="anchor"></a><h4 class="code-header">type <a class="associatedtype">Output</a> = <a class="struct" href="struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a></h4></section></summary><div class='docblock'>The resulting type after applying the <code>-</code> operator.</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.sub-4" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/chrono/offset/fixed.rs.html#222-224">source</a><a href="#method.sub-4" class="anchor"></a><h4 class="code-header">fn <a class="fnname">sub</a>(self, rhs: <a class="struct" href="../offset/struct.FixedOffset.html" title="struct chrono::offset::FixedOffset">FixedOffset</a>) -&gt; <a class="struct" href="struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a></h4></section></summary><div class='docblock'>Performs the <code>-</code> operation. <a>Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-Sub%3CMonths%3E-for-NaiveDateTime" class="impl has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#1617-1623">source</a><a href="#impl-Sub%3CMonths%3E-for-NaiveDateTime" class="anchor"></a><h3 class="code-header">impl Sub&lt;<a class="struct" href="../struct.Months.html" title="struct chrono::Months">Months</a>&gt; for <a class="struct" href="struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a></h3></section></summary><div class="docblock"><p>A subtraction of Months from <code>NaiveDateTime</code> clamped to valid days in resulting month.</p>
<h4 id="panics-2"><a href="#panics-2">Panics</a></h4>
<p>Panics if the resulting date would be out of range.</p>
<h4 id="example-51"><a href="#example-51">Example</a></h4>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>chrono::{Months, NaiveDate};
<span class="macro">assert_eq!</span>(
NaiveDate::from_ymd_opt(<span class="number">2014</span>, <span class="number">01</span>, <span class="number">01</span>).unwrap().and_hms_opt(<span class="number">01</span>, <span class="number">00</span>, <span class="number">00</span>).unwrap() - Months::new(<span class="number">11</span>),
NaiveDate::from_ymd_opt(<span class="number">2013</span>, <span class="number">02</span>, <span class="number">01</span>).unwrap().and_hms_opt(<span class="number">01</span>, <span class="number">00</span>, <span class="number">00</span>).unwrap()
);
<span class="macro">assert_eq!</span>(
NaiveDate::from_ymd_opt(<span class="number">2014</span>, <span class="number">01</span>, <span class="number">01</span>).unwrap().and_hms_opt(<span class="number">00</span>, <span class="number">02</span>, <span class="number">00</span>).unwrap() - Months::new(<span class="number">12</span>),
NaiveDate::from_ymd_opt(<span class="number">2013</span>, <span class="number">01</span>, <span class="number">01</span>).unwrap().and_hms_opt(<span class="number">00</span>, <span class="number">02</span>, <span class="number">00</span>).unwrap()
);
<span class="macro">assert_eq!</span>(
NaiveDate::from_ymd_opt(<span class="number">2014</span>, <span class="number">01</span>, <span class="number">01</span>).unwrap().and_hms_opt(<span class="number">00</span>, <span class="number">00</span>, <span class="number">03</span>).unwrap() - Months::new(<span class="number">13</span>),
NaiveDate::from_ymd_opt(<span class="number">2012</span>, <span class="number">12</span>, <span class="number">01</span>).unwrap().and_hms_opt(<span class="number">00</span>, <span class="number">00</span>, <span class="number">03</span>).unwrap()
);</code></pre></div>
</div><div class="impl-items"><details class="rustdoc-toggle" open><summary><section id="associatedtype.Output-3" class="associatedtype trait-impl has-srclink"><a href="#associatedtype.Output-3" class="anchor"></a><h4 class="code-header">type <a class="associatedtype">Output</a> = <a class="struct" href="struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a></h4></section></summary><div class='docblock'>The resulting type after applying the <code>-</code> operator.</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.sub-1" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#1620-1622">source</a><a href="#method.sub-1" class="anchor"></a><h4 class="code-header">fn <a class="fnname">sub</a>(self, rhs: <a class="struct" href="../struct.Months.html" title="struct chrono::Months">Months</a>) -&gt; Self::Output</h4></section></summary><div class='docblock'>Performs the <code>-</code> operation. <a>Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-Sub%3CNaiveDateTime%3E-for-NaiveDateTime" class="impl has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#1664-1671">source</a><a href="#impl-Sub%3CNaiveDateTime%3E-for-NaiveDateTime" class="anchor"></a><h3 class="code-header">impl Sub&lt;<a class="struct" href="struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a>&gt; for <a class="struct" href="struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a></h3></section></summary><div class="docblock"><p>Subtracts another <code>NaiveDateTime</code> from the current date and time.
This does not overflow or underflow at all.</p>
<p>As a part of Chrono’s <a href="./struct.NaiveTime.html#leap-second-handling">leap second handling</a>,
the subtraction assumes that <strong>there is no leap second ever</strong>,
except when any of the <code>NaiveDateTime</code>s themselves represents a leap second
in which case the assumption becomes that
<strong>there are exactly one (or two) leap second(s) ever</strong>.</p>
<p>The implementation is a wrapper around <a href="struct.NaiveDateTime.html#method.signed_duration_since" title="NaiveDateTime::signed_duration_since"><code>NaiveDateTime::signed_duration_since</code></a>.</p>
<h4 id="example-52"><a href="#example-52">Example</a></h4>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>chrono::{Duration, NaiveDate};
<span class="kw">let </span>from_ymd = |y, m, d| NaiveDate::from_ymd_opt(y, m, d).unwrap();
<span class="kw">let </span>d = from_ymd(<span class="number">2016</span>, <span class="number">7</span>, <span class="number">8</span>);
<span class="macro">assert_eq!</span>(d.and_hms_opt(<span class="number">3</span>, <span class="number">5</span>, <span class="number">7</span>).unwrap() - d.and_hms_opt(<span class="number">2</span>, <span class="number">4</span>, <span class="number">6</span>).unwrap(), Duration::seconds(<span class="number">3600 </span>+ <span class="number">60 </span>+ <span class="number">1</span>));
<span class="comment">// July 8 is 190th day in the year 2016
</span><span class="kw">let </span>d0 = from_ymd(<span class="number">2016</span>, <span class="number">1</span>, <span class="number">1</span>);
<span class="macro">assert_eq!</span>(d.and_hms_milli_opt(<span class="number">0</span>, <span class="number">7</span>, <span class="number">6</span>, <span class="number">500</span>).unwrap() - d0.and_hms_opt(<span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>).unwrap(),
Duration::seconds(<span class="number">189 </span>* <span class="number">86_400 </span>+ <span class="number">7 </span>* <span class="number">60 </span>+ <span class="number">6</span>) + Duration::milliseconds(<span class="number">500</span>));</code></pre></div>
<p>Leap seconds are handled, but the subtraction assumes that no other leap
seconds happened.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>leap = from_ymd(<span class="number">2015</span>, <span class="number">6</span>, <span class="number">30</span>).and_hms_milli_opt(<span class="number">23</span>, <span class="number">59</span>, <span class="number">59</span>, <span class="number">1_500</span>).unwrap();
<span class="macro">assert_eq!</span>(leap - from_ymd(<span class="number">2015</span>, <span class="number">6</span>, <span class="number">30</span>).and_hms_opt(<span class="number">23</span>, <span class="number">0</span>, <span class="number">0</span>).unwrap(),
Duration::seconds(<span class="number">3600</span>) + Duration::milliseconds(<span class="number">500</span>));
<span class="macro">assert_eq!</span>(from_ymd(<span class="number">2015</span>, <span class="number">7</span>, <span class="number">1</span>).and_hms_opt(<span class="number">1</span>, <span class="number">0</span>, <span class="number">0</span>).unwrap() - leap,
Duration::seconds(<span class="number">3600</span>) - Duration::milliseconds(<span class="number">500</span>));</code></pre></div>
</div><div class="impl-items"><details class="rustdoc-toggle" open><summary><section id="associatedtype.Output-4" class="associatedtype trait-impl has-srclink"><a href="#associatedtype.Output-4" class="anchor"></a><h4 class="code-header">type <a class="associatedtype">Output</a> = <a class="struct" href="../struct.Duration.html" title="struct chrono::Duration">Duration</a></h4></section></summary><div class='docblock'>The resulting type after applying the <code>-</code> operator.</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.sub-2" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#1668-1670">source</a><a href="#method.sub-2" class="anchor"></a><h4 class="code-header">fn <a class="fnname">sub</a>(self, rhs: <a class="struct" href="struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a>) -&gt; <a class="struct" href="../struct.Duration.html" title="struct chrono::Duration">OldDuration</a></h4></section></summary><div class='docblock'>Performs the <code>-</code> operation. <a>Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-SubAssign%3CDuration%3E-for-NaiveDateTime" class="impl has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#1586-1591">source</a><a href="#impl-SubAssign%3CDuration%3E-for-NaiveDateTime" class="anchor"></a><h3 class="code-header">impl SubAssign&lt;<a class="struct" href="../struct.Duration.html" title="struct chrono::Duration">Duration</a>&gt; for <a class="struct" href="struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.sub_assign" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#1588-1590">source</a><a href="#method.sub_assign" class="anchor"></a><h4 class="code-header">fn <a class="fnname">sub_assign</a>(&amp;mut self, rhs: <a class="struct" href="../struct.Duration.html" title="struct chrono::Duration">OldDuration</a>)</h4></section></summary><div class='docblock'>Performs the <code>-=</code> operation. <a>Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-Timelike-for-NaiveDateTime" class="impl has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#1255-1416">source</a><a href="#impl-Timelike-for-NaiveDateTime" class="anchor"></a><h3 class="code-header">impl <a class="trait" href="../trait.Timelike.html" title="trait chrono::Timelike">Timelike</a> for <a class="struct" href="struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.hour" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#1269-1271">source</a><a href="#method.hour" class="anchor"></a><h4 class="code-header">fn <a href="../trait.Timelike.html#tymethod.hour" class="fnname">hour</a>(&amp;self) -&gt; u32</h4></section></summary><div class="docblock"><p>Returns the hour number from 0 to 23.</p>
<p>See also the <a href="struct.NaiveTime.html#method.hour" title="NaiveTime::hour"><code>NaiveTime::hour</code></a> method.</p>
<h5 id="example-40"><a href="#example-40">Example</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>chrono::{NaiveDate, NaiveDateTime, Timelike};
<span class="kw">let </span>dt: NaiveDateTime = NaiveDate::from_ymd_opt(<span class="number">2015</span>, <span class="number">9</span>, <span class="number">8</span>).unwrap().and_hms_milli_opt(<span class="number">12</span>, <span class="number">34</span>, <span class="number">56</span>, <span class="number">789</span>).unwrap();
<span class="macro">assert_eq!</span>(dt.hour(), <span class="number">12</span>);</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.minute" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#1286-1288">source</a><a href="#method.minute" class="anchor"></a><h4 class="code-header">fn <a href="../trait.Timelike.html#tymethod.minute" class="fnname">minute</a>(&amp;self) -&gt; u32</h4></section></summary><div class="docblock"><p>Returns the minute number from 0 to 59.</p>
<p>See also the <a href="struct.NaiveTime.html#method.minute" title="NaiveTime::minute"><code>NaiveTime::minute</code></a> method.</p>
<h5 id="example-41"><a href="#example-41">Example</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>chrono::{NaiveDate, NaiveDateTime, Timelike};
<span class="kw">let </span>dt: NaiveDateTime = NaiveDate::from_ymd_opt(<span class="number">2015</span>, <span class="number">9</span>, <span class="number">8</span>).unwrap().and_hms_milli_opt(<span class="number">12</span>, <span class="number">34</span>, <span class="number">56</span>, <span class="number">789</span>).unwrap();
<span class="macro">assert_eq!</span>(dt.minute(), <span class="number">34</span>);</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.second" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#1303-1305">source</a><a href="#method.second" class="anchor"></a><h4 class="code-header">fn <a href="../trait.Timelike.html#tymethod.second" class="fnname">second</a>(&amp;self) -&gt; u32</h4></section></summary><div class="docblock"><p>Returns the second number from 0 to 59.</p>
<p>See also the <a href="struct.NaiveTime.html#method.second" title="NaiveTime::second"><code>NaiveTime::second</code></a> method.</p>
<h5 id="example-42"><a href="#example-42">Example</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>chrono::{NaiveDate, NaiveDateTime, Timelike};
<span class="kw">let </span>dt: NaiveDateTime = NaiveDate::from_ymd_opt(<span class="number">2015</span>, <span class="number">9</span>, <span class="number">8</span>).unwrap().and_hms_milli_opt(<span class="number">12</span>, <span class="number">34</span>, <span class="number">56</span>, <span class="number">789</span>).unwrap();
<span class="macro">assert_eq!</span>(dt.second(), <span class="number">56</span>);</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.nanosecond" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#1322-1324">source</a><a href="#method.nanosecond" class="anchor"></a><h4 class="code-header">fn <a href="../trait.Timelike.html#tymethod.nanosecond" class="fnname">nanosecond</a>(&amp;self) -&gt; u32</h4></section></summary><div class="docblock"><p>Returns the number of nanoseconds since the whole non-leap second.
The range from 1,000,000,000 to 1,999,999,999 represents
the <a href="./struct.NaiveTime.html#leap-second-handling">leap second</a>.</p>
<p>See also the <a href="struct.NaiveTime.html#method.nanosecond" title="NaiveTime::nanosecond"><code>NaiveTime::nanosecond</code></a> method.</p>
<h5 id="example-43"><a href="#example-43">Example</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>chrono::{NaiveDate, NaiveDateTime, Timelike};
<span class="kw">let </span>dt: NaiveDateTime = NaiveDate::from_ymd_opt(<span class="number">2015</span>, <span class="number">9</span>, <span class="number">8</span>).unwrap().and_hms_milli_opt(<span class="number">12</span>, <span class="number">34</span>, <span class="number">56</span>, <span class="number">789</span>).unwrap();
<span class="macro">assert_eq!</span>(dt.nanosecond(), <span class="number">789_000_000</span>);</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.with_hour" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#1343-1345">source</a><a href="#method.with_hour" class="anchor"></a><h4 class="code-header">fn <a href="../trait.Timelike.html#tymethod.with_hour" class="fnname">with_hour</a>(&amp;self, hour: u32) -&gt; Option&lt;<a class="struct" href="struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a>&gt;</h4></section></summary><div class="docblock"><p>Makes a new <code>NaiveDateTime</code> with the hour number changed.</p>
<p>Returns <code>None</code> when the resulting <code>NaiveDateTime</code> would be invalid.</p>
<p>See also the <a href="struct.NaiveTime.html#method.with_hour" title="NaiveTime::with_hour"><code>NaiveTime::with_hour</code></a> method.</p>
<h5 id="example-44"><a href="#example-44">Example</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>chrono::{NaiveDate, NaiveDateTime, Timelike};
<span class="kw">let </span>dt: NaiveDateTime = NaiveDate::from_ymd_opt(<span class="number">2015</span>, <span class="number">9</span>, <span class="number">8</span>).unwrap().and_hms_milli_opt(<span class="number">12</span>, <span class="number">34</span>, <span class="number">56</span>, <span class="number">789</span>).unwrap();
<span class="macro">assert_eq!</span>(dt.with_hour(<span class="number">7</span>),
<span class="prelude-val">Some</span>(NaiveDate::from_ymd_opt(<span class="number">2015</span>, <span class="number">9</span>, <span class="number">8</span>).unwrap().and_hms_milli_opt(<span class="number">7</span>, <span class="number">34</span>, <span class="number">56</span>, <span class="number">789</span>).unwrap()));
<span class="macro">assert_eq!</span>(dt.with_hour(<span class="number">24</span>), <span class="prelude-val">None</span>);</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.with_minute" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#1365-1367">source</a><a href="#method.with_minute" class="anchor"></a><h4 class="code-header">fn <a href="../trait.Timelike.html#tymethod.with_minute" class="fnname">with_minute</a>(&amp;self, min: u32) -&gt; Option&lt;<a class="struct" href="struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a>&gt;</h4></section></summary><div class="docblock"><p>Makes a new <code>NaiveDateTime</code> with the minute number changed.</p>
<p>Returns <code>None</code> when the resulting <code>NaiveDateTime</code> would be invalid.</p>
<p>See also the
<a href="struct.NaiveTime.html#method.with_minute" title="NaiveTime::with_minute"><code>NaiveTime::with_minute</code></a> method.</p>
<h5 id="example-45"><a href="#example-45">Example</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>chrono::{NaiveDate, NaiveDateTime, Timelike};
<span class="kw">let </span>dt: NaiveDateTime = NaiveDate::from_ymd_opt(<span class="number">2015</span>, <span class="number">9</span>, <span class="number">8</span>).unwrap().and_hms_milli_opt(<span class="number">12</span>, <span class="number">34</span>, <span class="number">56</span>, <span class="number">789</span>).unwrap();
<span class="macro">assert_eq!</span>(dt.with_minute(<span class="number">45</span>),
<span class="prelude-val">Some</span>(NaiveDate::from_ymd_opt(<span class="number">2015</span>, <span class="number">9</span>, <span class="number">8</span>).unwrap().and_hms_milli_opt(<span class="number">12</span>, <span class="number">45</span>, <span class="number">56</span>, <span class="number">789</span>).unwrap()));
<span class="macro">assert_eq!</span>(dt.with_minute(<span class="number">60</span>), <span class="prelude-val">None</span>);</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.with_second" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#1388-1390">source</a><a href="#method.with_second" class="anchor"></a><h4 class="code-header">fn <a href="../trait.Timelike.html#tymethod.with_second" class="fnname">with_second</a>(&amp;self, sec: u32) -&gt; Option&lt;<a class="struct" href="struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a>&gt;</h4></section></summary><div class="docblock"><p>Makes a new <code>NaiveDateTime</code> with the second number changed.</p>
<p>Returns <code>None</code> when the resulting <code>NaiveDateTime</code> would be invalid. As
with the <a href="struct.NaiveDateTime.html#method.second" title="NaiveDateTime::second"><code>NaiveDateTime::second</code></a> method, the input range is
restricted to 0 through 59.</p>
<p>See also the <a href="struct.NaiveTime.html#method.with_second" title="NaiveTime::with_second"><code>NaiveTime::with_second</code></a> method.</p>
<h5 id="example-46"><a href="#example-46">Example</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>chrono::{NaiveDate, NaiveDateTime, Timelike};
<span class="kw">let </span>dt: NaiveDateTime = NaiveDate::from_ymd_opt(<span class="number">2015</span>, <span class="number">9</span>, <span class="number">8</span>).unwrap().and_hms_milli_opt(<span class="number">12</span>, <span class="number">34</span>, <span class="number">56</span>, <span class="number">789</span>).unwrap();
<span class="macro">assert_eq!</span>(dt.with_second(<span class="number">17</span>),
<span class="prelude-val">Some</span>(NaiveDate::from_ymd_opt(<span class="number">2015</span>, <span class="number">9</span>, <span class="number">8</span>).unwrap().and_hms_milli_opt(<span class="number">12</span>, <span class="number">34</span>, <span class="number">17</span>, <span class="number">789</span>).unwrap()));
<span class="macro">assert_eq!</span>(dt.with_second(<span class="number">60</span>), <span class="prelude-val">None</span>);</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.with_nanosecond" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#1413-1415">source</a><a href="#method.with_nanosecond" class="anchor"></a><h4 class="code-header">fn <a href="../trait.Timelike.html#tymethod.with_nanosecond" class="fnname">with_nanosecond</a>(&amp;self, nano: u32) -&gt; Option&lt;<a class="struct" href="struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a>&gt;</h4></section></summary><div class="docblock"><p>Makes a new <code>NaiveDateTime</code> with nanoseconds since the whole non-leap second changed.</p>
<p>Returns <code>None</code> when the resulting <code>NaiveDateTime</code> would be invalid.
As with the <a href="struct.NaiveDateTime.html#method.nanosecond" title="NaiveDateTime::nanosecond"><code>NaiveDateTime::nanosecond</code></a> method,
the input range can exceed 1,000,000,000 for leap seconds.</p>
<p>See also the <a href="struct.NaiveTime.html#method.with_nanosecond" title="NaiveTime::with_nanosecond"><code>NaiveTime::with_nanosecond</code></a> method.</p>
<h5 id="example-47"><a href="#example-47">Example</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>chrono::{NaiveDate, NaiveDateTime, Timelike};
<span class="kw">let </span>dt: NaiveDateTime = NaiveDate::from_ymd_opt(<span class="number">2015</span>, <span class="number">9</span>, <span class="number">8</span>).unwrap().and_hms_milli_opt(<span class="number">12</span>, <span class="number">34</span>, <span class="number">56</span>, <span class="number">789</span>).unwrap();
<span class="macro">assert_eq!</span>(dt.with_nanosecond(<span class="number">333_333_333</span>),
<span class="prelude-val">Some</span>(NaiveDate::from_ymd_opt(<span class="number">2015</span>, <span class="number">9</span>, <span class="number">8</span>).unwrap().and_hms_nano_opt(<span class="number">12</span>, <span class="number">34</span>, <span class="number">56</span>, <span class="number">333_333_333</span>).unwrap()));
<span class="macro">assert_eq!</span>(dt.with_nanosecond(<span class="number">1_333_333_333</span>), <span class="comment">// leap second
</span><span class="prelude-val">Some</span>(NaiveDate::from_ymd_opt(<span class="number">2015</span>, <span class="number">9</span>, <span class="number">8</span>).unwrap().and_hms_nano_opt(<span class="number">12</span>, <span class="number">34</span>, <span class="number">56</span>, <span class="number">1_333_333_333</span>).unwrap()));
<span class="macro">assert_eq!</span>(dt.with_nanosecond(<span class="number">2_000_000_000</span>), <span class="prelude-val">None</span>);</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.hour12" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/chrono/traits.rs.html#129-136">source</a><a href="#method.hour12" class="anchor"></a><h4 class="code-header">fn <a href="../trait.Timelike.html#method.hour12" class="fnname">hour12</a>(&amp;self) -&gt; (bool, u32)</h4></section></summary><div class='docblock'>Returns the hour number from 1 to 12 with a boolean flag,
which is false for AM and true for PM. <a href="../trait.Timelike.html#method.hour12">Read more</a></div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.num_seconds_from_midnight" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/chrono/traits.rs.html#175-177">source</a><a href="#method.num_seconds_from_midnight" class="anchor"></a><h4 class="code-header">fn <a href="../trait.Timelike.html#method.num_seconds_from_midnight" class="fnname">num_seconds_from_midnight</a>(&amp;self) -&gt; u32</h4></section></summary><div class='docblock'>Returns the number of non-leap seconds past the last midnight.</div></details></div></details><section id="impl-Copy-for-NaiveDateTime" class="impl has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#74">source</a><a href="#impl-Copy-for-NaiveDateTime" class="anchor"></a><h3 class="code-header">impl Copy for <a class="struct" href="struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a></h3></section><section id="impl-Eq-for-NaiveDateTime" class="impl has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#74">source</a><a href="#impl-Eq-for-NaiveDateTime" class="anchor"></a><h3 class="code-header">impl Eq for <a class="struct" href="struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a></h3></section><section id="impl-StructuralEq-for-NaiveDateTime" class="impl has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#74">source</a><a href="#impl-StructuralEq-for-NaiveDateTime" class="anchor"></a><h3 class="code-header">impl StructuralEq for <a class="struct" href="struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a></h3></section><section id="impl-StructuralPartialEq-for-NaiveDateTime" class="impl has-srclink"><a class="srclink rightside" href="../../src/chrono/naive/datetime/mod.rs.html#74">source</a><a href="#impl-StructuralPartialEq-for-NaiveDateTime" class="anchor"></a><h3 class="code-header">impl StructuralPartialEq for <a class="struct" href="struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a></h3></section></div><h2 id="synthetic-implementations" class="small-section-header">Auto Trait Implementations<a href="#synthetic-implementations" class="anchor"></a></h2><div id="synthetic-implementations-list"><section id="impl-RefUnwindSafe-for-NaiveDateTime" class="impl has-srclink"><a href="#impl-RefUnwindSafe-for-NaiveDateTime" class="anchor"></a><h3 class="code-header">impl RefUnwindSafe for <a class="struct" href="struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a></h3></section><section id="impl-Send-for-NaiveDateTime" class="impl has-srclink"><a href="#impl-Send-for-NaiveDateTime" class="anchor"></a><h3 class="code-header">impl Send for <a class="struct" href="struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a></h3></section><section id="impl-Sync-for-NaiveDateTime" class="impl has-srclink"><a href="#impl-Sync-for-NaiveDateTime" class="anchor"></a><h3 class="code-header">impl Sync for <a class="struct" href="struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a></h3></section><section id="impl-Unpin-for-NaiveDateTime" class="impl has-srclink"><a href="#impl-Unpin-for-NaiveDateTime" class="anchor"></a><h3 class="code-header">impl Unpin for <a class="struct" href="struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a></h3></section><section id="impl-UnwindSafe-for-NaiveDateTime" class="impl has-srclink"><a href="#impl-UnwindSafe-for-NaiveDateTime" class="anchor"></a><h3 class="code-header">impl UnwindSafe for <a class="struct" href="struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a></h3></section></div><h2 id="blanket-implementations" class="small-section-header">Blanket Implementations<a href="#blanket-implementations" class="anchor"></a></h2><div id="blanket-implementations-list"><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-Any-for-NaiveDateTime" class="impl has-srclink"><a href="#impl-Any-for-NaiveDateTime" class="anchor"></a><h3 class="code-header">impl&lt;T&gt; Any for T<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: 'static + ?Sized,</span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.type_id" class="method trait-impl has-srclink"><a href="#method.type_id" class="anchor"></a><h4 class="code-header">fn <a class="fnname">type_id</a>(&amp;self) -&gt; TypeId</h4></section></summary><div class='docblock'>Gets the <code>TypeId</code> of <code>self</code>. <a>Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-Borrow%3CT%3E-for-NaiveDateTime" class="impl has-srclink"><a href="#impl-Borrow%3CT%3E-for-NaiveDateTime" class="anchor"></a><h3 class="code-header">impl&lt;T&gt; Borrow&lt;T&gt; for T<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: ?Sized,</span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.borrow" class="method trait-impl has-srclink"><span class="since rightside" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/91522" title="Tracking issue for const_borrow">unstable</a></span><a href="#method.borrow" class="anchor"></a><h4 class="code-header">fn <a class="fnname">borrow</a>(&amp;self) -&gt; &amp;T</h4></section></summary><div class='docblock'>Immutably borrows from an owned value. <a>Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-BorrowMut%3CT%3E-for-NaiveDateTime" class="impl has-srclink"><a href="#impl-BorrowMut%3CT%3E-for-NaiveDateTime" class="anchor"></a><h3 class="code-header">impl&lt;T&gt; BorrowMut&lt;T&gt; for T<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: ?Sized,</span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.borrow_mut" class="method trait-impl has-srclink"><span class="since rightside" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/91522" title="Tracking issue for const_borrow">unstable</a></span><a href="#method.borrow_mut" class="anchor"></a><h4 class="code-header">fn <a class="fnname">borrow_mut</a>(&amp;mut self) -&gt; &amp;mut T</h4></section></summary><div class='docblock'>Mutably borrows from an owned value. <a>Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-From%3CT%3E-for-NaiveDateTime" class="impl has-srclink"><a href="#impl-From%3CT%3E-for-NaiveDateTime" class="anchor"></a><h3 class="code-header">impl&lt;T&gt; From&lt;T&gt; for T</h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.from-1" class="method trait-impl has-srclink"><span class="since rightside" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/88674" title="Tracking issue for const_convert">unstable</a></span><a href="#method.from-1" class="anchor"></a><h4 class="code-header">fn <a class="fnname">from</a>(t: T) -&gt; T</h4></section></summary><div class="docblock"><p>Returns the argument unchanged.</p>
</div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-Into%3CU%3E-for-NaiveDateTime" class="impl has-srclink"><a href="#impl-Into%3CU%3E-for-NaiveDateTime" class="anchor"></a><h3 class="code-header">impl&lt;T, U&gt; Into&lt;U&gt; for T<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;U: From&lt;T&gt;,</span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.into" class="method trait-impl has-srclink"><span class="since rightside" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/88674" title="Tracking issue for const_convert">unstable</a></span><a href="#method.into" class="anchor"></a><h4 class="code-header">fn <a class="fnname">into</a>(self) -&gt; U</h4></section></summary><div class="docblock"><p>Calls <code>U::from(self)</code>.</p>
<p>That is, this conversion is whatever the implementation of
<code>[From]&lt;T&gt; for U</code> chooses to do.</p>
</div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-ToOwned-for-NaiveDateTime" class="impl has-srclink"><a href="#impl-ToOwned-for-NaiveDateTime" class="anchor"></a><h3 class="code-header">impl&lt;T&gt; ToOwned for T<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: Clone,</span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle" open><summary><section id="associatedtype.Owned" class="associatedtype trait-impl has-srclink"><a href="#associatedtype.Owned" class="anchor"></a><h4 class="code-header">type <a class="associatedtype">Owned</a> = T</h4></section></summary><div class='docblock'>The resulting type after obtaining ownership.</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.to_owned" class="method trait-impl has-srclink"><a href="#method.to_owned" class="anchor"></a><h4 class="code-header">fn <a class="fnname">to_owned</a>(&amp;self) -&gt; T</h4></section></summary><div class='docblock'>Creates owned data from borrowed data, usually by cloning. <a>Read more</a></div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.clone_into" class="method trait-impl has-srclink"><a href="#method.clone_into" class="anchor"></a><h4 class="code-header">fn <a class="fnname">clone_into</a>(&amp;self, target: &amp;mut T)</h4></section></summary><div class='docblock'>Uses borrowed data to replace owned data, usually by cloning. <a>Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-ToString-for-NaiveDateTime" class="impl has-srclink"><a href="#impl-ToString-for-NaiveDateTime" class="anchor"></a><h3 class="code-header">impl&lt;T&gt; ToString for T<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: Display + ?Sized,</span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.to_string" class="method trait-impl has-srclink"><a href="#method.to_string" class="anchor"></a><h4 class="code-header">default fn <a class="fnname">to_string</a>(&amp;self) -&gt; String</h4></section></summary><div class='docblock'>Converts the given value to a <code>String</code>. <a>Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-TryFrom%3CU%3E-for-NaiveDateTime" class="impl has-srclink"><a href="#impl-TryFrom%3CU%3E-for-NaiveDateTime" class="anchor"></a><h3 class="code-header">impl&lt;T, U&gt; TryFrom&lt;U&gt; for T<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;U: Into&lt;T&gt;,</span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle" open><summary><section id="associatedtype.Error-1" class="associatedtype trait-impl has-srclink"><a href="#associatedtype.Error-1" class="anchor"></a><h4 class="code-header">type <a class="associatedtype">Error</a> = Infallible</h4></section></summary><div class='docblock'>The type returned in the event of a conversion error.</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.try_from" class="method trait-impl has-srclink"><span class="since rightside" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/88674" title="Tracking issue for const_convert">unstable</a></span><a href="#method.try_from" class="anchor"></a><h4 class="code-header">fn <a class="fnname">try_from</a>(value: U) -&gt; Result&lt;T, &lt;T as TryFrom&lt;U&gt;&gt;::Error&gt;</h4></section></summary><div class='docblock'>Performs the conversion.</div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-TryInto%3CU%3E-for-NaiveDateTime" class="impl has-srclink"><a href="#impl-TryInto%3CU%3E-for-NaiveDateTime" class="anchor"></a><h3 class="code-header">impl&lt;T, U&gt; TryInto&lt;U&gt; for T<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;U: TryFrom&lt;T&gt;,</span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle" open><summary><section id="associatedtype.Error" class="associatedtype trait-impl has-srclink"><a href="#associatedtype.Error" class="anchor"></a><h4 class="code-header">type <a class="associatedtype">Error</a> = &lt;U as TryFrom&lt;T&gt;&gt;::Error</h4></section></summary><div class='docblock'>The type returned in the event of a conversion error.</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.try_into" class="method trait-impl has-srclink"><span class="since rightside" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/88674" title="Tracking issue for const_convert">unstable</a></span><a href="#method.try_into" class="anchor"></a><h4 class="code-header">fn <a class="fnname">try_into</a>(self) -&gt; Result&lt;U, &lt;U as TryFrom&lt;T&gt;&gt;::Error&gt;</h4></section></summary><div class='docblock'>Performs the conversion.</div></details></div></details></div></section></div></main><div id="rustdoc-vars" data-root-path="../../" data-current-crate="chrono" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.66.0-nightly (5c8bff74b 2022-10-21)" ></div></body></html>