Function format
fn format<impl AsRef<[u8]>: AsRef<[u8]>, impl Into<BrokenDownTime>: Into<BrokenDownTime>>(format: impl AsRef<[u8]>, broken_down_time: impl Into<BrokenDownTime>) -> Result<alloc::string::String, crate::Error>
Format the given broken down time using the format string given.
See the module documentation for details on what's supported.
This routine is like BrokenDownTime::format, but may be more
convenient to call. Also, it returns a String instead of accepting a
fmt::Write trait implementation to write to.
Note that broken_down_time can be anything that can be converted into
it. This includes, for example, Zoned, Timestamp, DateTime,
Date and Time.
Errors
This returns an error when formatting failed. Formatting can fail either
because of an invalid format string, or if formatting requires a field in
BrokenDownTime to be set that isn't. For example, trying to format a
DateTime with the %z specifier will fail because a DateTime has no
time zone or offset information associated with it.
Example
This example shows how to format a Zoned into something resembling a RFC
2822 datetime:
use ;
let zdt = date.at.in_tz?;
let string = format?;
assert_eq!;
# Ok::
Of course, one should prefer using the fmt::rfc2822
module, which contains a dedicated RFC 2822 printer.
Example: date-like output
While the output of the Unix date command is likely locale specific,
this is what it looks like on my system:
use ;
let zdt = date.at.in_tz?;
let string = format?;
assert_eq!;
# Ok::
Example: RFC 3339 compatible output with fractional seconds
use ;
let zdt = date
.at
.in_tz?;
let string = format?;
assert_eq!;
# Ok::