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 > 

Similar Posts

  • Emacs Tips and Howtos

    With Emacs, I feel happy. I love the rich functions of Emacs, such as compiling, quickly jumping to the lines with compilation error and debugging with gdb, and more. I ever wrote small tips posts about Emacs before. But it is a good idea to put them together and keep adding new ones. Here comes…

  • Linux timer sources

    Linux supports different timer sources and a machine can have multiple ones. How to find the available Linux timer source and the current one used? Find the current timer source: $ cat /sys/devices/system/clocksource/clocksource0/current_clocksource Find all available timer sources: $ cat /sys/devices/system/clocksource/clocksource0/available_clocksource Read more: Force Linux to reboot Wireless driver in Linux Mint for HP Mini…

  • MySQL at Facebook

    Facebook uses lots MySQL databases. Any information about how Facebook scales MySQL? Some information on the Web: MySQL at Facebook’s page https://www.facebook.com/MySQLatFacebook?filter=1 A post by Ryan Thiessen, Database Operations at Facebook on Quora: http://www.quora.com/Facebook-Engineering/How-does-Facebook-structure-MySQL-so-that-it-is-robust-and-scalable And more: http://mashable.com/2011/12/15/facebook-timeline-mysql/ http://gigaom.com/2011/12/06/facebook-shares-some-secrets-on-making-mysql-scale/ http://www.wired.com/wiredenterprise/2011/12/facebook-timeline-anatomy “A lot of people are surprised that for this shiny new thing for Facebook, we’re using…

Leave a Reply

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