How to get the epoch timestamp in PHP?
Posted on In QAIn PHP, how to get the epoch timestamp, the number of seconds passed since the epoch?
In PHP, you can use the time()
function.
ts = time();
To get the microsecond together too as a float number, use the microtime(true)
function.
ts2 = microtime(true);
Example:
$ php -a
Interactive shell
php > echo time() . PHP_EOL;
1491473013
php > echo microtime(true) . PHP_EOL;
1491473017.2061
php >