HomeMenu
Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

localtime

Description

The localtime of Date / Time for PHP gets the local time.

Syntax

localtime(
    ?int $timestamp = null,
    bool $associative = false
): array

Parameters

timestamp

The optional timestamp parameter is an int Unix timestamp that defaults to the current local time if timestamp is omitted or null. In other words, it defaults to the value of time().

associative

Determines whether the function should return a regular, numerically indexed array, or an associative one.

Return

If associative is set to false or not supplied then the array is returned as a regular, numerically indexed array.

If associative is set to true then localtime() returns an associative array containing the elements of the structure returned by the C function call to localtime.

KeyDescriptionExample
"tm_sec"seconds0 - 59
"tm_min"minutes0 - 59
"tm_hour"hours0 - 23
"tm_mday"day of the month1 - 31
"tm_mon"month of the year0 - 11 (January - December)
"tm_year"years since 1900
"tm_wday"day of the week0 - 6 (Sunday - Saturday)
"tm_yday"day of the year0 - 365
"tm_isdst"daylight saving timenegative, 0, or 1 (unknown, no, or yes)

Examples

1 · void

<?

$return = localtime();

print_r($return);
Array
(
    [0] => 46
    [1] => 2
    [2] => 2
    [3] => 15
    [4] => 0
    [5] => 126
    [6] => 4
    [7] => 14
    [8] => 0
)

2 · timestamp

<?

$timestamp = time();

$return = localtime($timestamp);

print_r($return);
Array
(
    [0] => 46
    [1] => 2
    [2] => 2
    [3] => 15
    [4] => 0
    [5] => 126
    [6] => 4
    [7] => 14
    [8] => 0
)

3 · associative

<?

$timestamp = null;
$associative = true;

$return = localtime($timestamp, $associative);

print_r($return);
Array
(
    [tm_sec] => 47
    [tm_min] => 2
    [tm_hour] => 2
    [tm_mday] => 15
    [tm_mon] => 0
    [tm_year] => 126
    [tm_wday] => 4
    [tm_yday] => 14
    [tm_isdst] => 0
)