The localtime() function returns the local time.
PHP localtime() Function has the following syntax.
localtime(timestamp,is_assoc);
Parameter | Is Required | Description |
---|---|---|
timestamp | Optional. | Unix timestamp that defaults to the current local time, time(), if no timestamp is specified |
is_assoc | Optional. | whether to return an associative or indexed array. |
Possible values for is_assoc.
The keys of the associative array are:
PHP localtime() Function returns an array that contains the components of a Unix timestamp.
Print local time as an indexed and as an associative array:
<?php
print_r(localtime());
echo "\m";
print_r(localtime(time(),true));
?>
The code above generates the following result.