localtime

Get the local time

Syntax

localtime ([ int $timestamp = time() [, bool $is_associative = FALSE ]] ) : array

Parameters

timestamp

The optional timestamp parameter 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().

is_associative

If set to FALSE or not supplied then the array is returned as a regular, numerically indexed array. If the argument is set to TRUE then localtime() returns 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, 0 to 59
"tm_min"minutes, 0 to 59
"tm_hour"hours, 0 to 23
"tm_mday"day of the month, 1 to 31
"tm_mon"month of the year, 0 (Jan) to 11 (Dec)
"tm_year"years since 1900
"tm_wday"day of the week, 0 (Sun) to 6 (Sat)
"tm_yday"day of the year, 0 to 365
"tm_isdst"is daylight savings time in effect? Positive if yes, 0 if not, negative if unknown.

Return

Examples

<?

$localtime = localtime();
$localtime_assoc = localtime(time(), true);
print_r($localtime);
print_r($localtime_assoc);

?>
Array
(
    [0] => 11
    [1] => 41
    [2] => 15
    [3] => 24
    [4] => 8
    [5] => 122
    [6] => 6
    [7] => 266
    [8] => 0
)
Array
(
    [tm_sec] => 11
    [tm_min] => 41
    [tm_hour] => 15
    [tm_mday] => 24
    [tm_mon] => 8
    [tm_year] => 122
    [tm_wday] => 6
    [tm_yday] => 266
    [tm_isdst] => 0
)

PHP

HomeMenu