Unix Timestamp in PHP
Use the `time()` function and `DateTime` class from the standard library. Both available since PHP 5.2 - no Composer dependencies needed.
Common Operations
Get current Unix timestamp
$ts = time(); // 1706745600
Convert Unix timestamp to date string
$date = date('Y-m-d H:i:s', 1706745600);
// '2024-01-31 22:40:00'
Convert date string to Unix timestamp
$ts = strtotime('2024-01-31 22:40:00 UTC');
// 1706740800
Format as ISO 8601
$iso = date('c', 1706745600);
// '2024-01-31T22:40:00+00:00'
Use DateTime for timezone-aware work
$dt = new DateTime('@1706745600');
$dt->setTimezone(new DateTimeZone('America/Los_Angeles'));
echo $dt->format('Y-m-d H:i:s T');
// '2024-01-31 14:40:00 PST'