PHP localtime() Function

6 Jan 2025 | 1 min read

This PHP localtime() function is used to print the time in the form of indexed and associative array. It returns the local time.

Syntax

Parameters

ParameterDescriptionRequired/Optional
timestampSpecifies a Unix timestampoptional
Is_assocSpecifies whether to return an associative array or indexed array.optional

Example 1

Output:

 Array ( [0] => 45 [1] => 50 [2] => 6 [3] => 9 [4] => 7 [5] => 118 [6] => 4 [7] => 220 [8] => 0 ) Array ( [tm_sec] => 45 [tm_min] => 50 [tm_hour] => 6 [tm_mday] => 9 [tm_mon] => 7 [tm_year] => 118 [tm_wday] => 4 [tm_yday] => 220 [tm_isdst] => 0 ) 

Example 2

Output:

 Array ( [0] => 26 [1] => 54 [2] => 6 [3] => 9 [4] => 7 [5] => 118 [6] => 4 [7] => 220 [8] => 0 ) Array ( [tm_sec] => 26 [tm_min] => 54 [tm_hour] => 6 [tm_mday] => 9 [tm_mon] => 7 [tm_year] => 118 [tm_wday] => 4 [tm_yday] => 220 [tm_isdst] => 0 )