How To Get Current Timestamp In PHP

There is multiple ways how to get current timestamp in PHP.

Using function time

Function time returns current Unix timestamp (number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT).


echo time();
# 1544509489		

Using function microtime

Function microtime returns current Unix timestamp with microseconds.


echo microtime(true);
# 1544509489.13	

Using class DateTime

Class DateTime provides an object oriented approach for date and time manipulation.


$d1 = new Datetime();
echo $d1->format('U');
# 1544509489	

$d2 = new Datetime("now");
echo $d2->format('U');
# 1544509489
This website uses cookies to ensure you get the best experience on our website. More info