PHP Unix Timestamp Converter

Convert Unix timestamps in PHP with live parser and DateTime snippets. time(), @timestamp, and timezones.

⏱ UnixLi — Live Tool All processing local · No data sent
—
unix seconds · now

Smart Universal Parser

// Paste Unix seconds/ms, ISO 8601, RFC 2822, or a human date.

Developer Snippets

// Copy-ready code — current timestamp injected automatically.

Unix timestamps in PHP

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.

Current time and quick formatting

PHP
<?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, 2024

gmdate() 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 setTimezone

The @ 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 8
<?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.

Parsing dates to epoch with strtotime

strtotime() 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
<?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();                      // 1715429912

For 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').

Milliseconds from JavaScript clients

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.

Frameworks and Carbon

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.

Common PHP timestamp pitfalls

Frequently asked questions

How do I get the current Unix timestamp in PHP?

Call time(). It returns integer seconds since 1970-01-01 00:00:00 UTC. Use microtime(true) for float seconds with microsecond precision.

How do I convert a Unix timestamp to a date in PHP?

Use gmdate('Y-m-d H:i:s', $ts) for UTC, or (new DateTimeImmutable('@' . $ts))->setTimezone(new DateTimeZone('Europe/Paris')) for a specific zone.

Why does date() show a different time than gmdate()?

date() uses the default timezone from date.timezone or date_default_timezone_set(), while gmdate() always uses UTC.

What timezone does new DateTimeImmutable('@1715429912') use?

Always UTC (+00:00). The @ syntax ignores the default timezone. Call setTimezone() to display it elsewhere.

What does strtotime return on invalid input?

It returns false. Check with === false before using the result, or you may print 1970-01-01 by accident.

Is anything I paste sent to a server?

No. The converter and snippets on this page run entirely in your browser.

Related tools