How to get the epoch timestamp in PHP?

In 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 > 
Answered by dtivl.

Leave a Reply

Your email address will not be published. Required fields are marked *