Crates.io | date_time_formatter |
lib.rs | date_time_formatter |
version | 0.3.0 |
created_at | 2025-07-28 11:51:14.722118+00 |
updated_at | 2025-07-29 14:16:25.798151+00 |
description | date-time-formatter-rs is a Rust crate that provides a simple and efficient way to parse and format date and time values. It is a rewrite of a subset of the Java time library, and aims to match its behaviour. |
homepage | |
repository | |
max_upload_size | |
id | 1771070 |
size | 23,849,050 |
'date-time-formatter' is a Rust crate that provides a simple and efficient way to parse and format date and time values. It is a rewrite of a subset of the Java time library, and aims to match its behaviour.
This ports DateTimeFormatterBuilder 1:1 from Java into Rust, with the following simplifying assumptions:
Additionally, this provides logic for converting from the Parsed representation into a Chrono (Naive)DateTime, and back. The resolution from Parsed into Chrono aims to replicate the results of Java equivalents, but is not 1:1 port.
let parsing_formatter = DateTimeFormatter::of_pattern("yyyy-MM-dd'T'hh:mm:ss")?;
let printing_formatter = DateTimeFormatter::of_pattern(
"'Year:' yyyy, 'Month:' MM, 'Date:' dd, 'Hour:' hh, 'Minute:' mm, 'Second:' ss",
)?;
let original_string = "2025-05-13T14:30:00";
let parsed: Parsed = parsing_formatter.parse(original_string)?;
let recovered_string = printing_formatter.format(&parsed)?;
assert_eq!(
"Year: 2025, Month: 05, Date: 13, Hour: 14, Minute: 30, Second: 00",
recovered_string
);
Created by Shiv Bhatia