W3docs

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.

date(string $format, ?int $timestamp = null): string

Runs on our server: your input is sent to w3docs and executed by PHP 8.2 in a sandbox with no network. Do not paste passwords or personal data.

Samples

Every letter that is a format character is replaced; a backslash prints the next character as is.

Unix seconds = 2023-11-14 22:13:20 UTC.

Any PHP time zone identifier, such as UTC or Europe/Berlin. Set before the call.

4 / 6,000 bytes of input · limit 6,000 bytes (about 6,000 characters)

Result

Press Run (or Ctrl+Enter) to call date() on PHP 8.2. The typed result appears here.

Equivalent PHP

<?php
date_default_timezone_set('UTC');
$result = date('c', 1700000000);
var_dump($result);

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

One timestamp, a named zonephp
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:00

Frequently 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.