Python strftime() to Java DateTimeFormatter Converter
Paste a Python strftime() format to get the equivalent java.time.format.DateTimeFormatter pattern.
Close equivalent Covers the common case, but has documented behavioral differences.
- Python strftime()
%Y-%m-%d %H:%M:%S- Java DateTimeFormatter
yyyy-MM-dd HH:mm:ss
Main limitation: DateTimeFormatter, like date-fns, uses letter-repetition (`d` vs `dd`, `M`/`MM`/`MMM`/`MMMM`) instead of strftime's one-directive-per-meaning scheme.
How it differs
- DateTimeFormatter, like date-fns, uses letter-repetition (
dvsdd,M/MM/MMM/MMMM) instead of strftime's one-directive-per-meaning scheme. - Python's
%d(zero-padded day) always maps cleanly to Java'sdd, but strftime has no non-padded day directive at all, so there is nothing corresponding to Java's singledto convert *from* in this direction. - Java's
e/c(locale-dependent numeric weekday) are intentionally left unmapped here because their meaning shifts with the JVM's default locale, unlike strftime's%uwhich is always ISO-8601 (Monday=1).
Examples
Standard timestamp
| Python strftime() | %Y-%m-%d %H:%M:%S |
|---|---|
| Java DateTimeFormatter | yyyy-MM-dd HH:mm:ss |
Every directive maps to an equal-meaning Java pattern letter run.
Long-form date
| Python strftime() | %A, %B %d, %Y |
|---|---|
| Java DateTimeFormatter | EEEE, MMMM dd, yyyy |
Full weekday/month names and zero-padded day both convert exactly.
Edge cases
Edge case
Java literal text is quoted with single quotes exactly like date-fns, including doubled quotes ('') for a literal apostrophe.
Edge case
strftime's %f (microseconds, 6 digits) maps to Java's SSSSSS; Java's 3-digit SSS (milliseconds) has no strftime source since Python has no milliseconds-only directive.
References
- Python docs — strftime() and strptime() format codes (v3.x) — checked 2026-07-29
- Java SE docs — DateTimeFormatter (v21) — checked 2026-07-29
Last verified 2026-07-29.