localtime 


php apg

GETS the local time information of a specific instant.



<?php

arr localtime 
int|null $timestamp null bool $associative false 


where,

$timestamp The UNIX timestamp

$associative 
To control the format of the returned ARRAY

?>

 $timestamp 


If provided $timestamp has the same value provided by the time function.



 $associative 


To control the format of the returned ARRAY.

If $associative = FALSE or not provided returns a numerically indexed ARRAY.

If $associative = TRUE this function returns an associative ARRAY.



 ASSOCIATIVE ARRAY INDEXES for localtime 

KEY DESCRIPTION EXAMPLE RETURNED
tm_sec Numeric representation of seconds 0 to 59
tm_min Numeric representation of minutes 0 to 59
tm_hour Numeric representation of hours 0 to 23
tm_mday Numeric representation of the day of the month 1 to 31
tm_wday Numeric representation of the day of the week 0 for Sunday... 6 for Saturday
tm_mon Numeric representation of a month 0 for January to 11 for December
tm_year Value to be added to 1900 The year
tm_yday Numeric representation of the day of the year 0 to 365
tm_isdst DST ZERO
OUT DST less than ZERO
ed48




The $timestamp has the same value of time.

Since PHP 8.0.0 $timestamp is nullable.



  1 EXERCISE   

<table width="100%" cellspacing="5" cellpadding="5" 
border="1" align="center"><tbody>
<tr><td colspan="2">REGULAR NUMERICALY INDEXED ARRAY</td></tr><tr>
<td width="40%">KEY</td><td width="60%">ACTUAL VALUE
<br><?php echo 'PHP ' PHP_VERSION?></td></tr>
<?php

$lc01tm01 
localtime();

foreach(
$lc01tm01 as $lc01 => $l01)
{
    echo 
'<tr><td>' $lc01 '</td><td>'$l01 '</td></tr>';
}

?>
<tr><td colspan="2">ed48</td></tr></tbody></table>

 

  2 EXERCISE   

<table width="100%" cellspacing="5" cellpadding="5" 
border="1" align="center"><tbody>
<tr><td colspan="2">ASSOCIATIVE ARRAY</td></tr><tr>
<td width="40%">KEY</td><td width="60%">ACTUAL VALUE
<br><?php echo 'PHP ' PHP_VERSION?></td></tr>
<?php

$tmstp02 
time();

$isass02 TRUE;

$lctm02 localtime($tmstp02$isass02);

foreach(
$lctm02 as $lc02 => $l02)
{
    echo 
'<tr><td>' $lc02 '</td><td>'$l02 '</td></tr>';
}

?>
<tr><td colspan="2">ed48</td></tr></tbody></table> 


  3 EXERCISE   

<table width="100%" cellspacing="5" cellpadding="5" 
border="1" align="center"><tbody>
<tr><td colspan="2">ASSOCIATIVE ARRAY</td></tr><tr>
<td width="40%">KEY</td><td width="60%">ACTUAL VALUE
<br><?php echo 'PHP ' PHP_VERSION?></td></tr>
<?php

date_default_timezone_set
('Europe/Lisbon');
$tzref date_default_timezone_get();

$tmstp03 time();

$isass03 TRUE;

$lctm03 localtime($tmstp03$isass03);

foreach(
$lctm03 as $lc03 => $l03)
{
    echo 
'<tr><td>' $lc03 '</td><td>'$l03 '</td></tr>';
}

?>
<tr><td colspan="2">ed48</td></tr></tbody></table>