PHP Timestamp Converter
PHP has built-in support for Unix timestamps throughout its standard library. The time() function returns the current Unix timestamp in seconds, date() formats a timestamp as a string, and strtotime() parses a date string and returns a Unix timestamp. For more complex PHP timestamp handling, the DateTime and DateTimeImmutable classes provide an object-oriented API with full timezone support.
One important PHP-specific behavior: date() formats timestamps using the server's configured timezone by default. If your PHP application handles users in multiple timezones, always use gmdate() for UTC output or pass an explicit timezone to the DateTime class to avoid timezone surprises.
PHP timestamp cheat sheet
Current Unix timestamp: time()
Timestamp to formatted date (local tz): date('Y-m-d H:i:s', $ts)
Timestamp to formatted date (UTC): gmdate('Y-m-d H:i:s', $ts)
Timestamp to ISO 8601: date('c', $ts)
Date string to timestamp: strtotime('2026-04-17 10:35:00 UTC')
Microsecond timestamp: microtime(true)
Using the DateTime class (recommended for production)
$dt = new DateTime('@1700000000'); // '@' prefix = Unix timestamp
$dt->setTimezone(new DateTimeZone('Europe/Oslo'));
echo $dt->format('Y-m-d H:i:s T'); // "2023-11-14 23:13:20 CET"
// Date to timestamp
$ts = (new DateTime('2026-04-17 10:35:00', new DateTimeZone('UTC')))->getTimestamp();