DateTimeFormats: Parse date time by examples (no EEEE VV zzz)

1 byjy 1 5/10/2025, 9:16:24 PM github.com ↗

Comments (1)

byjy · 5h ago
DateTimeFormats is a Java library that lets you parse datetime strings by example — no need to remember pattern strings like "yyyy-MM-dd'T'HH:mm:ss.SSS zzz".

Parsing example string: "Tue, 2024-03-19 15:00:00 America/New_York"

→ inferred pattern: "E, yyyy-MM-dd HH:mm:ss VV"

Supports LocalDate, OffsetDateTime, ZonedDateTime, and Instant.

Ambiguity is deliberately rejected: "10/30/2025" is accepted, "01/02/2025" (ambiguous) is not.

Use parseToInstant(timeStr) or parseZonedDateTime(timeStr) for quick one-liner parsing.

For better performance in loops: use formatOf(...) once and reuse the formatter.

All inferred patterns are verified using DateTimeFormatter.parse() — no false positives. If it parses, it roundtrips.

Project: https://github.com/google/mug

Javadoc: https://google.github.io/mug/apidocs/com/google/mu/time/Date...

Feedback welcome — edge cases, weird formats, you name it.