pub fn strftime(time: &impl Time, format: &str) -> Result<String, Error>
Available on crate feature
alloc
only.Expand description
Format a time implementation with the specified UTF-8 format string.
See the crate-level documentation for a complete description of possible format specifiers.
§Allocations
This strftime
implementation writes its output to a heap-allocated
Vec
. The implementation exclusively uses fallible allocation APIs
like Vec::try_reserve
. This function will return Error::OutOfMemory
if there is an allocation failure.
§Examples
use strftime::string::strftime;
use strftime::Time;
// Not shown: create a time implementation with the year 1970
// let time = ...;
assert_eq!(time.year(), 1970);
assert_eq!(strftime(&time, "%Y")?, "1970");
§Errors
Can produce an Error
when the formatting fails.