strftime::fmt

Function strftime

Source
pub fn strftime(
    time: &impl Time,
    format: &str,
    buf: &mut dyn Write,
) -> Result<(), Error>
Expand description

Format a time implementation with the specified UTF-8 format string, writing to the provided core::fmt::Write object.

See the crate-level documentation for a complete description of possible format specifiers.

§Allocations

This strftime implementation makes no heap allocations on its own, but the provided writer may allocate.

§Examples

use strftime::fmt::strftime;
use strftime::Time;

// Not shown: create a time implementation with the year 1970
// let time = ...;
assert_eq!(time.year(), 1970);

let mut buf = String::new();
strftime(&time, "%Y", &mut buf)?;
assert_eq!(buf, "1970");

§Errors

Can produce an Error when the formatting fails.