PHP localtime() Function

Example

Output local time in the form of a numeric array and an associative array:

<?php
print_r(localtime());
echo "<br><br>";
print_r(localtime(time(),true));
?>

Run Example

Definition and Usage

The localtime() function returns local time.

Syntax

localtime(timestamp,is_assoc);
Parameter Description
timestamp Optional. Specifies Unix timestamp. If not specified timestampis specified, then the default is the current local time time().
is_assoc

Optional. Specifies whether to return an associative array or an indexed array. If FALSE, returns an indexed array. If TRUE, returns an associative array. The default is FALSE.

The key names of the associated arrays are as follows:

  • [tm_sec] - Seconds
  • [tm_min] - Minutes
  • [tm_hour] - Hour
  • [tm_mday] - Day of the month
  • [tm_mon] - Month of the year, starting from 0 for January
  • [tm_year] - Year, starting from 1900
  • [tm_wday] - Day of the week (Sunday=0)
  • [tm_yday] - Day of the year
  • [tm_isdst] - Whether daylight saving time is currently in effect

Technical Details

Return Value: Returns an array containing Unix timestamp components.
PHP Version: 4+
Update Log: PHP 5.1.0: Added E_STRICT and E_NOTICE timezone errors.