Document chrono
This commit is contained in:
parent
0506b328b5
commit
263bb0e68d
15
doc/api.rst
15
doc/api.rst
@ -415,18 +415,15 @@ For example::
|
|||||||
|
|
||||||
#include <fmt/chrono.h>
|
#include <fmt/chrono.h>
|
||||||
|
|
||||||
int main() {
|
std::time_t t = std::time(nullptr);
|
||||||
|
// Prints "The date is 2020-11-07." (with the current date):
|
||||||
|
fmt::print("The date is {:%Y-%m-%d}.", fmt::localtime(t));
|
||||||
|
|
||||||
using namespace std::literals::chrono_literals;
|
using namespace std::literals::chrono_literals;
|
||||||
|
// Prints "Default format: 42s 100ms":
|
||||||
fmt::print("Default format: {} {}\n", 42s, 100ms);
|
fmt::print("Default format: {} {}\n", 42s, 100ms);
|
||||||
|
// Prints "strftime-like format: 03:15:30":
|
||||||
fmt::print("strftime-like format: {:%H:%M:%S}\n", 3h + 15min + 30s);
|
fmt::print("strftime-like format: {:%H:%M:%S}\n", 3h + 15min + 30s);
|
||||||
}
|
|
||||||
|
|
||||||
prints:
|
|
||||||
|
|
||||||
.. code:: none
|
|
||||||
|
|
||||||
Default format: 42s 100ms
|
|
||||||
strftime-like format: 03:15:30
|
|
||||||
|
|
||||||
Chrono format specifications are described in :ref:`chrono-specs`.
|
Chrono format specifications are described in :ref:`chrono-specs`.
|
||||||
|
|
||||||
|
@ -325,9 +325,11 @@ Literal chars are copied unchanged to the output. Precision is valid only for
|
|||||||
``std::chrono::duration`` types with a floating-point representation type.
|
``std::chrono::duration`` types with a floating-point representation type.
|
||||||
|
|
||||||
*conversion_spec* are conversion specifiers documented in `strftime
|
*conversion_spec* are conversion specifiers documented in `strftime
|
||||||
<http://en.cppreference.com/w/cpp/chrono/c/strftime>`_. Specifiers that have a
|
<http://en.cppreference.com/w/cpp/chrono/c/strftime>`_ for ``std::tm`` and
|
||||||
calendaric component such as `'d'` are valid only for ``std::tm`` and not
|
in `Meaning of conversion specifiers <https://eel.is/c++draft/time.format>`
|
||||||
durations or time points.
|
for chrono durations and time points. Specifiers that have a calendaric
|
||||||
|
component such as `'d'` are valid only for ``std::tm`` and not durations or time
|
||||||
|
points.
|
||||||
|
|
||||||
.. _formatexamples:
|
.. _formatexamples:
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user