[PHP] Format a Unix timestamp as a date string

Created on November 30, 2026

You can create a DateTime object from Unix seconds by passing the number as a string prefixed with @. Set the desired time zone before formatting it if the date should reflect local time.

<?php

$date = new DateTime('@1650000000');
$date->setTimezone(new DateTimeZone('Asia/Tokyo'));
echo $date->format('Y-m-d'), PHP_EOL;
2022-04-15
PHP