Home/Guides/Convert PHP Timestamp to Date

PHP Date Guides

Convert PHP Timestamp to Date

How to convert Unix timestamps to formatted dates in PHP and avoid seconds versus milliseconds bugs.

A Unix timestamp is a number representing seconds since the Unix epoch. PHP date functions can format it directly.

Code examples

$timestamp = 1719820800;

echo date('Y-m-d H:i:s', $timestamp);

With DateTimeImmutable:

$date = (new DateTimeImmutable())->setTimestamp($timestamp);
echo $date->format('c');

Common errors

JavaScript timestamps are milliseconds. PHP timestamps are usually seconds. Mixing them is the most common conversion bug.

Try the PHP Timestamp Converter.

FAQ

Are PHP timestamps in seconds?

Yes, normal Unix timestamps in PHP are seconds.

How do I convert JavaScript timestamps for PHP?

Divide JavaScript millisecond timestamps by 1000 before using them as PHP timestamps.

Related tools

Related guides