PHP | localtime() Function Last Updated : 28 Aug, 2018 Comments Improve Suggest changes Like Article Like Report 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. Syntax: 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. Exceptions: 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: Program 1: php <?php // Displaying the local time as // a numerically indexed array echo ("The local time is :"); print_r(localtime()); ?> Output: The local time is :Array ( [0] => 22 [1] => 24 [2] => 10 [3] => 28 [4] => 7 [5] => 118 [6] => 2 [7] => 239 [8] => 0 ) Program 2: php <?php // Displaying the local time as // an associative array echo ("The local time is :"); print_r(localtime(time(), true)); ?> Output: 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 ) Related Articles: PHP | idate() Function PHP | time() Function PHP | strptime() Function Reference: http://php.net/manual/en/function.localtime.php Comment More infoAdvertise with us Next Article PHP | localtime() Function S Shubrodeep Banerjee Follow Improve Article Tags : Misc Web Technologies PHP PHP-date-time PHP-function +1 More Practice Tags : Misc Similar Reads PHP | mktime() Function The mktime() function is an inbuilt function in PHP which is used to return the Unix timestamp for a date. The timestamp returns a long integer containing the number of seconds between the Unix Epoch (January 1, 1970, 00:00:00 GMT) and the time specified. The hour, minute, second, month, day and yea 2 min read PHP | hrtime() Function The hrtime() function is an inbuilt function in PHP which returns the high-resolution time of the system. Syntax: mixed hrtime( bool $is_num_return ); Parameter: This function accepts a single parameter as mentioned above and described below: $is_num_return: It is optional parameter of Boolean type. 1 min read PHP | microtime() Function The microtime() function is an inbuilt function in PHP which is used to return the current Unix timestamp with microseconds. The $get_as_float is sent as a parameter to the microtime() function and it returns the string microsec sec by default. Syntax: microtime( $get_as_float ) Parameters: This fun 2 min read localtime() function in C++ The localtime() function is defined in the ctime header file. The localtime() function converts the given time since epoch to calendar time which is expressed as local time. Syntax: tm* localtime(const time_t* time_ptr); Parameter: This function accepts a parameter time_ptr which represents the poin 1 min read PHP | idate() Function The idate() function is an inbuilt function in PHP which is used to format a local time/date as an integer. The $format and $timestamp are sent as parameters to the idate() function and it returns an integer formatted according to the specified format using the given timestamp. Unlike the function d 2 min read Like