Home >>PHP Date Time Functions >PHP localtime() Function
PHP localtime() function is used to return the local time. It accepts two parameters $timestamp and $is_associative. It returns an array containing the components of a Unix timestamp.
Syntax:
localtime(timestamp, is_assoc);
Parameter | Description |
---|---|
timestamp | This is an optional parameter. This parameter defines a Unix timestamp. |
is_assoc | This is an optional parameter. This parameter whether to return an associative or indexed array. |
Here is an example of localtime() function in PHP:
<html> <body> <pre> <?php print_r(localtime()); print_r(localtime(1581669933)); ?> </pre> </body> </html>
Array ( [0] => 55 [1] => 6 [2] => 11 [3] => 1 [4] => 1 [5] => 120 [6] => 6 [7] => 31 [8] => 0 ) Array ( [0] => 33 [1] => 45 [2] => 8 [3] => 14 [4] => 1 [5] => 120 [6] => 5 [7] => 44 [8] => 0 )
Example 2:
<html> <body> <pre> <?php print_r(localtime(1581669933)); print_r(localtime(1581669933,true)); ?> </pre> </body> </html>
Array ( [0] => 33 [1] => 45 [2] => 8 [3] => 14 [4] => 1 [5] => 120 [6] => 5 [7] => 44 [8] => 0 ) Array ( [tm_sec] => 33 [tm_min] => 45 [tm_hour] => 8 [tm_mday] => 14 [tm_mon] => 1 [tm_year] => 120 [tm_wday] => 5 [tm_yday] => 44 [tm_isdst] => 0 )