Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PHP localtime() Function

PHP localtime() Function

PHP Date/Time PHP Date/Time Reference Manual

Example

Output the local time as both a numeric array and an associative array:


"; print_r(localtime(time(),true)); ?>

Run Example »


Definition and Usage

The localtime() function returns the local time.

Syntax

localtime(

timestamp,is_assoc);

Parameters Description
timestamp Optional. Specifies a Unix timestamp. If timestampis not specified, it defaults to the current local time, time().
is_assoc Optional. Specifies whether to return an associative or numeric array. If FALSE, a numeric array is returned. If TRUE, an associative array is returned. Default is FALSE.

The keys of the associative array are as follows:

  • [tm_sec] - Seconds
  • [tm_min] - Minutes
  • [tm_hour] - Hours
  • [tm_mday] - Day of the month
  • [tm_mon] - Month of the year, starting at 0 for January
  • [tm_year] - Years since 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 the components of a Unix timestamp.
    PHP Version: 4+
    Changelog: PHP 5.1.0: E_STRICT and E_NOTICE time zone errors were added.

    PHP Date/Time PHP Date/Time Reference Manual