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();
# 1569251045		

Using function microtime

Function microtime returns current Unix timestamp with microseconds.

echo microtime(true);
# 1569251045.1088	

Using class DateTime

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

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

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