Convert Unix timestamps in PHP with live parser and DateTime snippets. time(), @timestamp, and timezones.
Smart Universal Parser
// Paste Unix seconds/ms, ISO 8601, RFC 2822, or a human date.
Developer Snippets
// Copy-ready code — current timestamp injected automatically.
PHP has handled Unix time natively for decades. time() returns the current epoch seconds, date() formats them, and the object API (DateTimeImmutable, DateTimeZone) takes care of time zones and daylight saving time. The live parser above lets you check any value, whether seconds, milliseconds, ISO 8601, or RFC 2822, and the snippet panel generates PHP code with the current timestamp filled in. Everything runs in your browser; nothing is sent to a PHP server or anywhere else.
<?php
$now = time(); // e.g. 1715429912
echo gmdate('Y-m-d H:i:s', 1715429912); // 2024-05-11 12:18:32 (UTC)
echo date('l, F j, Y', 1715429912); // Saturday, May 11, 2024gmdate() always formats in UTC. date() formats in the default timezone, which comes from date.timezone in php.ini or from date_default_timezone_set(). Two servers with different settings print different local times for the same timestamp, so decide the zone explicitly instead of relying on configuration.
DateTimeImmutable and setTimezoneThe @ prefix creates a date from Unix seconds, and that object is always in UTC (+00:00), whatever the default timezone. Convert it for display with setTimezone(). Because the class is immutable, this returns a new object and never changes the original, which avoids a common source of bugs with the older mutable DateTime.
<?php
$utc = new DateTimeImmutable('@1715429912');
echo $utc->format(DATE_ATOM); // 2024-05-11T12:18:32+00:00
$paris = $utc->setTimezone(new DateTimeZone('Europe/Paris'));
echo $paris->format('Y-m-d H:i:s T'); // 2024-05-11 14:18:32 CEST
echo $paris->getTimestamp(); // 1715429912 (unchanged)That shows 1715429912 is Saturday, May 11, 2024 at 12:18:32 UTC, 14:18:32 in Paris during summer time. The timestamp stays the same; only the displayed wall-clock time changes.
strtotimestrtotime() turns many English date strings into Unix seconds, and returns false when it cannot parse the input. Always check for false, and include a zone in the string or you will get the default timezone’s interpretation:
<?php
$ts = strtotime('2024-05-11 12:18:32 UTC'); // 1715429912
if ($ts === false) { throw new RuntimeException('Unparseable date'); }
$dt = new DateTimeImmutable('2024-05-11 12:18:32', new DateTimeZone('UTC'));
echo $dt->getTimestamp(); // 1715429912For strict formats, DateTimeImmutable::createFromFormat() is safer than free-form parsing. It also accepts U for Unix seconds and U.v for seconds with milliseconds, e.g. createFromFormat('U.v', '1715429912.123').
Front-ends often send Date.now() values in milliseconds. Convert with integer division, intdiv($ms, 1000), before passing them to date() or @. For the current time with sub-second precision in PHP itself, microtime(true) returns float seconds. The JavaScript timestamp page covers the client side of the same contract.
Laravel and many other projects use Carbon, which extends DateTime/DateTimeImmutable. Carbon::createFromTimestamp(1715429912) wraps the same epoch logic, but default-timezone behavior has changed between Carbon major versions. Pass the zone explicitly, for example Carbon::createFromTimestamp($ts, 'UTC'), so an upgrade can’t silently shift your output.
date.timezone. Set a zone explicitly with DateTimeZone in code paths that matter.DateTime. $d->modify('+1 day') changes the object in place, and every reference sees it. Prefer DateTimeImmutable.strtotime. Passing false into date() silently prints 1970-01-01.PHP_INT_SIZE === 8) are fine. Old 32-bit builds overflow after 2038-01-19 03:14:07 UTC.Call time(). It returns integer seconds since 1970-01-01 00:00:00 UTC. Use microtime(true) for float seconds with microsecond precision.
Use gmdate('Y-m-d H:i:s', $ts) for UTC, or (new DateTimeImmutable('@' . $ts))->setTimezone(new DateTimeZone('Europe/Paris')) for a specific zone.
date() uses the default timezone from date.timezone or date_default_timezone_set(), while gmdate() always uses UTC.
Always UTC (+00:00). The @ syntax ignores the default timezone. Call setTimezone() to display it elsewhere.
It returns false. Check with === false before using the result, or you may print 1970-01-01 by accident.
No. The converter and snippets on this page run entirely in your browser.