The localtime() function is an inbuilt function in PHP which is used to return the local time. The array returned by the localtime() function is similar to the structure returned by the C function call. The $timestamp and $is_associative are sent as parameters to the localtime() function and it returns an array that contains the components of a Unix timestamp.
array localtime( $timestamp, $is_associative )
Parameters: This function accepts two parameters as mentioned above and described below.
- $timestamp: It is an optional parameter which specifies the Unix timestamp. Its default value is current local time.
- $is_associative: It is an optional parameter which specifies whether to return an associative or indexed array. The value of associative array are:
- tm_sec: seconds, 0 to 59
- tm_min: minutes, 0 to 59
- tm_hour: hours, 0 to 23
- tm_mday: day of the month, 1 to 31
- tm_mon: month of the year, 0 (Jan) to 11 (Dec)
- tm_year: years since 1900
- tm_wday: day of the week, 0 (Sun) to 6 (Sat)
- tm_yday: day of the year, 0 to 365
- tm_isdst: is daylight savings time in effect? Positive if yes, 0 if not, negative if unknown.
Return Value: This function returns an array that contains the components of a Unix timestamp.
- The localtime() function generates a E_NOTICE if the time zone specified is not valid.
- The localtime() function generates a E_STRICT or E_WARNING message if using the system settings or the TZ environment variable
Below programs illustrate the localtime() function in PHP:
The local time is :Array (  => 22  => 24  => 10  => 28  => 7  => 118  => 2  => 239  => 0 )
The local time is :Array ( [tm_sec] => 23 [tm_min] => 24 [tm_hour] => 10 [tm_mday] => 28 [tm_mon] => 7 [tm_year] => 118 [tm_wday] => 2 [tm_yday] => 239 [tm_isdst] => 0 )
- PHP | Ds\Map put() Function
- CSS | var() Function
- p5.js | str() function
- p5.js | second() function
- D3.js | d3.map.set() Function
- p5.js | box() Function
- p5.js | value() Function
- PHP | Ds\Set add() Function
- p5.js | log() function
- CSS | hsl() Function
- p5.js | arc() Function
- PHP | pow( ) Function
- PHP | cos( ) Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.