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);


$ php -a
Interactive shell

php > echo time() . PHP_EOL;
php > echo microtime(true) . PHP_EOL;
php > 
Leave a Reply

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