Unix Timestamp in PHP
PHP's time() function returns the current Unix timestamp in seconds. For milliseconds, use microtime(). DateTime and Carbon are popular for date arithmetic.
Code Examples
Current timestamp (seconds)
time();
The simplest way. Returns the current Unix timestamp as an integer (seconds). Available in all PHP versions.
Current timestamp (milliseconds)
round(microtime(true) * 1000);
microtime(true) returns seconds as a float with microsecond precision. Multiply by 1000 and round for milliseconds.
Using DateTime class
$dt = new DateTime('now', new DateTimeZone('UTC'));
$timestamp = $dt->getTimestamp();Object-oriented approach. Useful when you're already working with DateTime objects.
Convert timestamp to date string
date('Y-m-d H:i:s', $timestamp);Format a Unix timestamp as a human-readable date. The second argument defaults to now if omitted.
Carbon (Laravel / popular library)
use Carbon\Carbon; Carbon::now()->timestamp;
Carbon is the standard date library in the Laravel ecosystem. ->timestamp returns seconds since epoch.
Note
PHP's time() returns seconds, consistent with C and Unix conventions. Unlike JavaScript and Java, PHP does not default to milliseconds. The microtime() function provides sub-second precision when needed.
Need to convert a specific timestamp? Use the live converter — paste any epoch value and see the human-readable date instantly.
← Open the converter