English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
PHP Date & Time Functions Manual
localtime() function
The localtime() function returns the local time as an array, with different parts of the time as elements of the array.
localtime($timestamp, \t$is_assoc)
Serial number | Parameters and descriptions |
---|---|
1 | timestamp(optional) This is an integer value representing the Unix timestamp of the local time. |
2 | is_assoc(optional) If set to FALSE or not provided, it returns a regular numeric indexed array. If the parameter is set to TRUE, the localtime() function returns an associative array containing all different units returned by the C localtime() function call. The different keys in the associative array are:
|
The PHP localtime() function returns an array representing the local time.
This function was initially introduced in PHP version4introduced and can be used in all higher versions.
The following examples demonstratelocaltime()Function usage-
<?php $time = localtime(); print_r($time); ?>Test and see‹/›
Output result
Array ( [0] => 50 [1] => 28 [2] => 13 [3] => 12 [4] => 4 [5] => 120 [6] => 2 [7] => 132 [8] => 0 )
Now, let's pass the timestamp parameter.-
<?php $timestamp = time(); $time = localtime($timestamp); print_r($time); ?>Test and see‹/›
Output result
Array ( [0] => 21 [1] => 54 [2] => 13 [3] => 12 [4] => 4 [5] => 120 [6] => 2 [7] => 132 [8] => 0 )
If you go through-
<?php $timestamp1 = time() - (23*12*30); print_r($timestamp1); print("\n"); $timestamp2 = time() + (23*12*30); print_r($timestamp2); ?>Test and see‹/›
Output result
Normal array: Array ( [0] => 23 [1] => 8 [2] => 14 [3] => 12 [4] => 4 [5] => 120 [6] => 2 [7] => 132 [8] => 0 ) Associative array: Array ( [tm_sec] => 23 [tm_min] => 8 [tm_hour] => 14 [tm_mday] => 12 [tm_mon] => 4 [tm_year] => 120 [tm_wday] => 2 [tm_yday] => 132 [tm_isdst] => 0 )