PHP Function Reference

PHP time() Function



The PHP time() function returns the current time measured in the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT).

Syntax

time()

Parameters

No parameter is required.

Return Value

Returns the current timestamp.

Example:

The example below shows the usage of time() function.

<?php
//getting current time measured in the number
//of seconds since the Unix Epoch
$currtime = time();
echo "Time elapsed since Unix Epoch: ".
    $currtime." seconds\n";

//using date() function to format the
//current time; the date() function uses
//time() as second parameter by default
echo  "Current time: ".date('Y-m-d') ."\n";

//getting formatted time for next week
echo  "Next Week: ".date('Y-m-d', strtotime('+1 week')) ."\n";
?>

The output of the above code will be:

Time elapsed since Unix Epoch: 1631161463 seconds
Current time: 2021-09-09
Next Week: 2021-09-16

❮ PHP Date and Time Reference