How to get the epoch timestamp in PHP?

In PHP, how to get the epoch timestamp, the number of seconds passed since the epoch?

asked May 23, 2017 by dtivl (2,500 points)

1 Answer

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 May 27, 2017 by dtivl (2,500 points)

Please log in or register to answer this question.

Related questions

1 answer
0 answers
1 answer
asked May 23, 2017 by dtivl (2,500 points)
1 answer
asked May 23, 2017 by dtivl (2,500 points)
1 answer
asked May 23, 2017 by dtivl (2,500 points)
1 answer
asked May 23, 2017 by dtivl (2,500 points)
1 answer
asked May 23, 2017 by dtivl (2,500 points)
1 answer
asked May 23, 2017 by dtivl (2,500 points)
Copyright © SysTutorials. User contributions licensed under cc-wiki with attribution required.
Hosted on Dreamhost

...