PHP date() to Java DateTimeFormatter Converter
Paste a PHP date() format string to get the equivalent java.time.format.DateTimeFormatter pattern.
Close equivalent Covers the common case, but has documented behavioral differences.
- PHP date()
Y-m-d H:i:s- Java DateTimeFormatter
yyyy-MM-dd HH:mm:ss
Main limitation: PHP's one-character-per-meaning tokens expand into Java's letter-repetition patterns — e.g. PHP's `Y` (4-digit year) becomes Java's `yyyy`, and `F` (full month name) becomes `MMMM`.
How it differs
- PHP's one-character-per-meaning tokens expand into Java's letter-repetition patterns — e.g. PHP's
Y(4-digit year) becomes Java'syyyy, andF(full month name) becomesMMMM. - PHP's
u(microseconds, 6 digits) maps to Java'sSSSSSS; PHP'sv(milliseconds, 3 digits) maps to Java'sSSS— both precisions are supported in this direction, unlike the strftime pairing. - PHP's
S(ordinal suffix) has no DateTimeFormatter equivalent; Java's pattern language has no built-in ordinal-suffix token at all.
Examples
Standard timestamp
| PHP date() | Y-m-d H:i:s |
|---|---|
| Java DateTimeFormatter | yyyy-MM-dd HH:mm:ss |
PHP's single-character tokens expand into Java's letter-repetition equivalents.
RFC-822-style log line
| PHP date() | D, d M Y H:i:s |
|---|---|
| Java DateTimeFormatter | EEE, dd MMM yyyy HH:mm:ss |
Short weekday/month names and zero-padded fields both convert exactly.
Edge cases
Edge case
A literal T in a PHP format (e.g. for an ISO-8601-style string) is escaped as \T in PHP but appears as 'T' (single-quoted) in the Java pattern — different escaping mechanisms, same intent.
Edge case
PHP's N (ISO-8601 numeric weekday, 1=Monday) has no direct DateTimeFormatter pattern letter mapped here, since Java's closest letter (e) is locale-dependent rather than guaranteed ISO — it is intentionally left unsupported rather than risk a wrong day number.
References
- PHP Manual — date() — checked 2026-07-29
- Java SE docs — DateTimeFormatter (v21) — checked 2026-07-29
Last verified 2026-07-29.