Home >Backend Development >PHP Tutorial >What is the difference between localtime and getdate in php?
I just read the document and I feel that these two functions are very similar. They both return arrays of date, time and other information based on the timestamp. And judging from the returned information, getdate can completely replace localtime. So what is the significance of localtime?
I just read the document and I feel that these two functions are very similar. They both return arrays of date, time and other information based on the timestamp. And judging from the returned information, getdate can completely replace localtime. So what is the significance of localtime?
localtime
In the array obtained, the year starts from 1900
<code> <?php $localtime = localtime(); $localtime_assoc = localtime(time(), true); //print_r($localtime); print_r($localtime_assoc); ?> <?php $today = getdate(); print_r($today); ?></code>
<code>Array ( [tm_sec] => 37 [tm_min] => 22 [tm_hour] => 3 [tm_mday] => 9 [tm_mon] => 9 [tm_year] => 116 [tm_wday] => 0 [tm_yday] => 282 [tm_isdst] => 0 ) Array ( [seconds] => 37 [minutes] => 22 [hours] => 3 [mday] => 9 [wday] => 0 [mon] => 10 [year] => 2016 [yday] => 282 [weekday] => Sunday [month] => October [0] => 1475983357 ) </code>