PHP Tutorial - PHP localtime() Function






Definition

The localtime() function returns the local time.

Syntax

PHP localtime() Function has the following syntax.

localtime(timestamp,is_assoc);

Parameter

ParameterIs RequiredDescription
timestampOptional.Unix timestamp that defaults to the current local time, time(), if no timestamp is specified
is_assocOptional.whether to return an associative or indexed array.

Possible values for is_assoc.

  • FALSE - means the array returned is an indexed array.
  • TRUE - means the array returned is an associative array. FALSE is default.

The keys of the associative array are:

  • [tm_sec] - seconds
  • [tm_min] - minutes
  • [tm_hour] - hour
  • [tm_mday] - day of the month
  • [tm_mon] - month of the year (January=0)
  • [tm_year] - Years since 1900
  • [tm_wday] - Day of the week (Sunday=0)
  • [tm_yday] - Day of the year
  • [tm_isdst] - Is daylight savings time in effect




Return

PHP localtime() Function returns an array that contains the components of a Unix timestamp.

Example

Print local time as an indexed and as an associative array:


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

The code above generates the following result.