Document chrono

This commit is contained in:
Victor Zverovich 2020-11-07 09:47:56 -08:00
parent 9795d87348
commit 4e426c19d0
2 changed files with 26 additions and 8 deletions

View File

@ -405,18 +405,30 @@ Using ``fmt::join``, you can separate tuple elements with a custom separator::
Date and Time Formatting Date and Time Formatting
======================== ========================
The library supports `strftime ``fmt/chrono.h`` provides formatters for
<http://en.cppreference.com/w/cpp/chrono/c/strftime>`_-like date and time
formatting:: * `std::chrono::duration <https://en.cppreference.com/w/cpp/chrono/duration>`_
* `std::chrono::time_point <https://en.cppreference.com/w/cpp/chrono/time_point>`_
* `std::tm <https://en.cppreference.com/w/cpp/chrono/c/tm>`_
For example::
#include <fmt/chrono.h> #include <fmt/chrono.h>
std::time_t t = std::time(nullptr); int main() {
// Prints "The date is 2016-04-29." (with the current date) using namespace std::literals::chrono_literals;
fmt::print("The date is {:%Y-%m-%d}.", fmt::localtime(t)); fmt::print("Default format: {} {}\n", 42s, 100ms);
fmt::print("strftime-like format: {:%H:%M:%S}\n", 3h + 15min + 30s);
}
The format string syntax is described in the documentation of prints::
`strftime <http://en.cppreference.com/w/cpp/chrono/c/strftime>`_.
Default format: 42s 100ms
strftime-like format: 03:15:30
Chrono format specifications are described in :ref:`chrono-specs`.
.. doxygenclass:: formatter<std::chrono::time_point<std::chrono::system_clock>, Char>
.. _compile-api: .. _compile-api:

View File

@ -321,6 +321,12 @@ Format specifications for chrono types have the following syntax:
: "q" | "Q" | "r" | "R" | "S" | "t" | "T" | "u" | "U" | "V" | : "q" | "Q" | "r" | "R" | "S" | "t" | "T" | "u" | "U" | "V" |
: "w" | "W" | "x" | "X" | "y" | "Y" | "z" | "Z" | "%" | : "w" | "W" | "x" | "X" | "y" | "Y" | "z" | "Z" | "%" |
Literal chars are copied unchanged to the output. Precision is valid only for
``std::chrono::duration`` types with a floating-point representation type.
*conversion_spec* are conversion specifiers documented in `strftime
<http://en.cppreference.com/w/cpp/chrono/c/strftime>`_.
.. _formatexamples: .. _formatexamples:
Format Examples Format Examples