PHP sandbox
PHP date() Online
Format a Unix timestamp with PHP date() format characters in any time zone. Runs on real PHP 8.2 on our server when you press Run.
About date()
date() formats a Unix timestamp as text. Every letter in the format that is a format character is replaced: Y is the four-digit year, m the zero-padded month, D the short weekday, P the UTC offset.
Letters that are not format characters are copied as they are, and a backslash prints the next character literally, so \T\o\d\a\y prints "Today". Because n, a, m and e are format characters, a format like $name prints a month, am/pm, another month and the zone name.
The output depends on the time zone, so the sandbox sets it explicitly with date_default_timezone_set() before calling date().
Worked example
date_default_timezone_set('America/New_York');
echo date('D, d M Y H:i:s P', 1700000000);
// Tue, 14 Nov 2023 17:13:20 -05:00Frequently asked questions
Why does date() print the wrong hour?
The default time zone is not the one you expect. Set it with date_default_timezone_set(), or use gmdate() for UTC.
How do I print a letter literally?
Escape it with a backslash, inside single quotes so PHP passes the backslash on: date('\a\t H:i') prints "at 17:13".
Is my input sent to a server?
Yes. These pages run real PHP 8.2 on the w3docs server, so the text you enter is sent there to run, in a sandbox with no network access. Do not paste passwords, keys or personal data.
How much input can I send?
Up to 6,000 bytes across all text fields, which is about 6,000 characters of plain text (accented letters and emoji take 2 to 4 bytes). Larger input is refused before anything is sent.