mirror of
https://github.com/OMGeeky/google-apis-rs.git
synced 2026-01-28 04:41:02 +01:00
30 lines
12 KiB
HTML
30 lines
12 KiB
HTML
<!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="Formatting (and parsing) utilities for date and time."><title>chrono::format - Rust</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/SourceSerif4-Regular-46f98efaafac5295.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/FiraSans-Regular-018c141bf0843ffd.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/FiraSans-Medium-8f9a781e4970d388.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2"><link rel="stylesheet" href="../../static.files/normalize-76eba96aa4d2e634.css"><link rel="stylesheet" href="../../static.files/rustdoc-ac92e1bbe349e143.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="chrono" data-themes="" data-resource-suffix="" data-rustdoc-version="1.76.0 (07dca489a 2024-02-04)" data-channel="1.76.0" data-search-js="search-2b6ce74ff89ae146.js" data-settings-js="settings-4313503d2e1961c2.js" ><script src="../../static.files/storage-f2adc0d6ca4d09fb.js"></script><script defer src="../sidebar-items.js"></script><script defer src="../../static.files/main-305769736d49e732.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-feafe1bb7466e4bd.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-16x16-8b506e7a72182f1c.png"><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-422f7d1d52889060.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-2c020d218678b618.svg"></head><body class="rustdoc mod"><!--[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">☰</button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../chrono/index.html">chrono</a><span class="version">0.4.31</span></h2></div><h2 class="location"><a href="#">Module format</a></h2><div class="sidebar-elems"><section><ul class="block"><li><a href="#reexports">Re-exports</a></li><li><a href="#modules">Modules</a></li><li><a href="#structs">Structs</a></li><li><a href="#enums">Enums</a></li><li><a href="#functions">Functions</a></li><li><a href="#types">Type Aliases</a></li></ul></section><h2><a href="../index.html">In crate chrono</a></h2></div></nav><div class="sidebar-resizer"></div>
|
||
<main><div class="width-limiter"><nav class="sub"><form class="search-form"><span></span><div id="sidebar-button" tabindex="-1"><a href="../../chrono/all.html" title="show sidebar"></a></div><input class="search-input" name="search" aria-label="Run search in the documentation" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><div id="help-button" tabindex="-1"><a href="../../help.html" title="help">?</a></div><div id="settings-menu" tabindex="-1"><a href="../../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../../static.files/wheel-7b819b6101059cd0.svg"></a></div></form></nav><section id="main-content" class="content"><div class="main-heading"><h1>Module <a href="../index.html">chrono</a>::<wbr><a class="mod" href="#">format</a><button id="copy-path" title="Copy item path to clipboard"><img src="../../static.files/clipboard-7571035ce49a181d.svg" width="19" height="18" alt="Copy item path"></button></h1><span class="out-of-band"><a class="src" href="../../src/chrono/format/mod.rs.html#4-544">source</a> · <button id="toggle-all-docs" title="collapse all docs">[<span>−</span>]</button></span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Formatting (and parsing) utilities for date and time.</p>
|
||
<p>This module provides the common types and routines to implement,
|
||
for example, <a href="../struct.DateTime.html#method.format"><code>DateTime::format</code></a> or
|
||
<a href="../struct.DateTime.html#method.parse_from_str"><code>DateTime::parse_from_str</code></a> methods.
|
||
For most cases you should use these high-level interfaces.</p>
|
||
<p>Internally the formatting and parsing shares the same abstract <strong>formatting items</strong>,
|
||
which are just an <a href="https://doc.rust-lang.org/std/iter/trait.Iterator.html"><code>Iterator</code></a> of
|
||
the <a href="./enum.Item.html"><code>Item</code></a> type.
|
||
They are generated from more readable <strong>format strings</strong>;
|
||
currently Chrono supports a built-in syntax closely resembling
|
||
C’s <code>strftime</code> format. The available options can be found <a href="./strftime/index.html">here</a>.</p>
|
||
<h2 id="example"><a href="#example">Example</a></h2>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>chrono::{NaiveDateTime, TimeZone, Utc};
|
||
|
||
<span class="kw">let </span>date_time = Utc.with_ymd_and_hms(<span class="number">2020</span>, <span class="number">11</span>, <span class="number">10</span>, <span class="number">0</span>, <span class="number">1</span>, <span class="number">32</span>).unwrap();
|
||
|
||
<span class="kw">let </span>formatted = <span class="macro">format!</span>(<span class="string">"{}"</span>, date_time.format(<span class="string">"%Y-%m-%d %H:%M:%S"</span>));
|
||
<span class="macro">assert_eq!</span>(formatted, <span class="string">"2020-11-10 00:01:32"</span>);
|
||
|
||
<span class="kw">let </span>parsed = NaiveDateTime::parse_from_str(<span class="kw-2">&</span>formatted, <span class="string">"%Y-%m-%d %H:%M:%S"</span>)<span class="question-mark">?</span>.and_utc();
|
||
<span class="macro">assert_eq!</span>(parsed, date_time);</code></pre></div>
|
||
</div></details><h2 id="reexports" class="section-header"><a href="#reexports">Re-exports</a></h2><ul class="item-table"><li><div class="item-name" id="reexport.StrftimeItems"><code>pub use strftime::<a class="struct" href="strftime/struct.StrftimeItems.html" title="struct chrono::format::strftime::StrftimeItems">StrftimeItems</a>;</code></div></li></ul><h2 id="modules" class="section-header"><a href="#modules">Modules</a></h2><ul class="item-table"><li><div class="item-name"><a class="mod" href="strftime/index.html" title="mod chrono::format::strftime">strftime</a></div><div class="desc docblock-short"><code>strftime</code>/<code>strptime</code>-inspired date and time formatting syntax.</div></li></ul><h2 id="structs" class="section-header"><a href="#structs">Structs</a></h2><ul class="item-table"><li><div class="item-name"><a class="struct" href="struct.DelayedFormat.html" title="struct chrono::format::DelayedFormat">DelayedFormat</a></div><div class="desc docblock-short">A <em>temporary</em> object which can be used as an argument to <code>format!</code> or others.
|
||
This is normally constructed via <code>format</code> methods of each date and time type.</div></li><li><div class="item-name"><a class="struct" href="struct.InternalFixed.html" title="struct chrono::format::InternalFixed">InternalFixed</a></div><div class="desc docblock-short">An opaque type representing fixed-format item types for internal uses only.</div></li><li><div class="item-name"><a class="struct" href="struct.InternalNumeric.html" title="struct chrono::format::InternalNumeric">InternalNumeric</a></div><div class="desc docblock-short">An opaque type representing numeric item types for internal uses only.</div></li><li><div class="item-name"><a class="struct" href="struct.OffsetFormat.html" title="struct chrono::format::OffsetFormat">OffsetFormat</a></div><div class="desc docblock-short">Type for specifying the format of UTC offsets.</div></li><li><div class="item-name"><a class="struct" href="struct.ParseError.html" title="struct chrono::format::ParseError">ParseError</a></div><div class="desc docblock-short">An error from the <code>parse</code> function.</div></li><li><div class="item-name"><a class="struct" href="struct.Parsed.html" title="struct chrono::format::Parsed">Parsed</a></div><div class="desc docblock-short">Parsed parts of date and time. There are two classes of methods:</div></li></ul><h2 id="enums" class="section-header"><a href="#enums">Enums</a></h2><ul class="item-table"><li><div class="item-name"><a class="enum" href="enum.Colons.html" title="enum chrono::format::Colons">Colons</a></div><div class="desc docblock-short">The separator between hours and minutes in an offset.</div></li><li><div class="item-name"><a class="enum" href="enum.Fixed.html" title="enum chrono::format::Fixed">Fixed</a></div><div class="desc docblock-short">Fixed-format item types.</div></li><li><div class="item-name"><a class="enum" href="enum.Item.html" title="enum chrono::format::Item">Item</a></div><div class="desc docblock-short">A single formatting item. This is used for both formatting and parsing.</div></li><li><div class="item-name"><a class="enum" href="enum.Numeric.html" title="enum chrono::format::Numeric">Numeric</a></div><div class="desc docblock-short">Numeric item types.
|
||
They have associated formatting width (FW) and parsing width (PW).</div></li><li><div class="item-name"><a class="enum" href="enum.OffsetPrecision.html" title="enum chrono::format::OffsetPrecision">OffsetPrecision</a></div><div class="desc docblock-short">The precision of an offset from UTC formatting item.</div></li><li><div class="item-name"><a class="enum" href="enum.Pad.html" title="enum chrono::format::Pad">Pad</a></div><div class="desc docblock-short">Padding characters for numeric items.</div></li><li><div class="item-name"><a class="enum" href="enum.ParseErrorKind.html" title="enum chrono::format::ParseErrorKind">ParseErrorKind</a></div><div class="desc docblock-short">The category of parse error</div></li></ul><h2 id="functions" class="section-header"><a href="#functions">Functions</a></h2><ul class="item-table"><li><div class="item-name"><a class="fn" href="fn.format.html" title="fn chrono::format::format">format</a></div><div class="desc docblock-short">Tries to format given arguments with given formatting items.
|
||
Internally used by <code>DelayedFormat</code>.</div></li><li><div class="item-name"><a class="fn" href="fn.format_item.html" title="fn chrono::format::format_item">format_item</a></div><div class="desc docblock-short">Formats single formatting item</div></li><li><div class="item-name"><a class="fn" href="fn.parse.html" title="fn chrono::format::parse">parse</a></div><div class="desc docblock-short">Tries to parse given string into <code>parsed</code> with given formatting items.
|
||
Returns <code>Ok</code> when the entire string has been parsed (otherwise <code>parsed</code> should not be used).
|
||
There should be no trailing string after parsing;
|
||
use a stray <a href="./enum.Item.html#variant.Space"><code>Item::Space</code></a> to trim whitespaces.</div></li><li><div class="item-name"><a class="fn" href="fn.parse_and_remainder.html" title="fn chrono::format::parse_and_remainder">parse_and_remainder</a></div><div class="desc docblock-short">Tries to parse given string into <code>parsed</code> with given formatting items.
|
||
Returns <code>Ok</code> with a slice of the unparsed remainder.</div></li></ul><h2 id="types" class="section-header"><a href="#types">Type Aliases</a></h2><ul class="item-table"><li><div class="item-name"><a class="type" href="type.ParseResult.html" title="type chrono::format::ParseResult">ParseResult</a></div><div class="desc docblock-short">Same as <code>Result<T, ParseError></code>.</div></li></ul></section></div></main></body></html> |