PHP Localtime () function

PHP

Syntax:
array localtime ($timestamp, $is_associative) 
Parameters:This function takes two parameters, as above and described below.
  • $timestamp:This is an optional parameter that specifies the Unix timestamp. Its default value is the current local time.
  • $is_associative:is an optional parameter that specifies whether to return an associative or indexed array. Associative array values:
    • 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 (January) to 11 (December)
    • tm_year:years since 1900
    • tm_wday:day of the week, from 0 (Sun) to 6 (Sat)
    • tm_yday:day of the year, from 0 to 365
    • tm_isdst:Is daylight saving time in effect? Positive if yes, 0 if not, negative if unknown.
Return value:This function returns an array that contains Unix timestamp components.Exceptions :
  • The localtime() function generates an E_NOTICE if the specified time zone is invalid.
  • The localtime() function generates an E_STRICT or E_WARNING message when using system settings or the TZ environment variable
The following programs illustrate the localtime() function in PHP:Program 1:  
// Display local time as
// numerically indexed array echo ( "The local time is:"
); print_r (localtime());  
?>
Exit:
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:  
// Display local time as
// associative array echo ( "The local time is:" ); print_r (localtime (time(), true));  
?>
Exit:
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
Link: http://php.net/manual/en/function.localtime.php



Get Solution for free from DataCamp guru