PHP - Function localtime()


Advertisements


Syntax

array localtime ( [int $timestamp [, bool $is_associative]] );

Definition and Usage

The localtime() function returns an array identical to that of the structure returned by the C function call.

Parameters

Sr.No Parameter & Description
1

timestamp

Optional. This is an integer Unix timestamp that defaults to the current local time if a timestamp is not given. In other words, it defaults to the value of time().

2

is_associative

Optional. If set to FALSE or not supplied than the array is returned as a regular, numerically indexed array. If the argument is set to TRUE then localtime() is an associative array containing all the different elements of the structure returned by the C function call to localtime.

The names of the different keys of the associative array are as follows −

  • [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 Value

Explained in Definition.

Example

Following is the usage of this function −

<?php
   $localtime = localtime();
   $localtime_assoc = localtime(time(), true);
   
   print_r($localtime);
   print_r($localtime_assoc);
?>

This will produce the following result −

Array (
   [0] => 24
   [1] => 3
   [2] => 19
   [3] => 3
   [4] => 3
   [5] => 105
   [6] => 0
   [7] => 92
   [8] => 1
)

Array (
   [tm_sec] => 24
   [tm_min] => 3
   [tm_hour] => 19
   [tm_mday] => 3
   [tm_mon] => 3
   [tm_year] => 105
   [tm_wday] => 0
   [tm_yday] => 92
   [tm_isdst] => 1
)

php_function_reference.htm