PHP localtime() Function

PHP localtime Function


Definition :

In php localtime() Function is inbuilt function.PHP localtime() function is used to return the local time. It accepts two parameters $timestamp and $is_associative. It returns an array containing the components of a Unix timestamp.

Syntax

  localtime(timestamp, is_assoc)

Parameter
Parameter Description
timestamp Optional. Specifies a Unix timestamp that defaults to the current local time, time(), if no timestamp is specified
is_assoc Optional. Specifies whether to return an associative or indexed array. FALSE = the array returned is an indexed array. TRUE = 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

Given below example print local time as an indexed and as an associative array:

Output :