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//w ww.j a  v a2  s  .  c o m
print_r(localtime());
echo "\m";
print_r(localtime(time(),true));
?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    Function reference »




PHP Array Functions
PHP Calendar Functions
PHP Class Functions
PHP Data Type Functions
PHP Date Functions
PHP File Functions
PHP Image Functions
PHP Math Functions
PHP MySQLi Functions
PHP SimpleXML Functions
PHP String Functions
PHP XML Functions
PHP Zip Functions