localtime()函數(shù)
localtime()函數(shù)以數(shù)組的形式返回本地時(shí)間,將時(shí)間的不同部分作為數(shù)組的元素。
localtime($timestamp, $is_assoc)
序號(hào) | 參數(shù)及說(shuō)明 |
---|---|
1 | timestamp(可選) 這是一個(gè)整數(shù)值,表示本地時(shí)間的Unix時(shí)間戳。 |
2 | is_assoc(可選) 如果設(shè)為 FALSE 或未提供則返回的是普通的數(shù)字索引數(shù)組。如果該參數(shù)設(shè)為 TRUE 則 localtime() 函數(shù)返回包含有所有從 C 的 localtime 函數(shù)調(diào)用所返回的不同單元的關(guān)聯(lián)數(shù)組。關(guān)聯(lián)數(shù)組中不同的鍵名為:
|
PHP localtime()函數(shù)返回一個(gè)表示本地時(shí)間的數(shù)組。
此函數(shù)最初是在PHP版本4中引入的,并且可以在所有更高版本中使用。
以下示例演示了localtime()函數(shù)的用法-
<?php $time = localtime(); print_r($time); ?>測(cè)試看看?/?
輸出結(jié)果
Array ( [0] => 50 [1] => 28 [2] => 13 [3] => 12 [4] => 4 [5] => 120 [6] => 2 [7] => 132 [8] => 0 )
現(xiàn)在,讓我們通過(guò)傳遞時(shí)間戳參數(shù)。-
<?php $timestamp = time(); $time = localtime($timestamp); print_r($time); ?>測(cè)試看看?/?
輸出結(jié)果
Array ( [0] => 21 [1] => 54 [2] => 13 [3] => 12 [4] => 4 [5] => 120 [6] => 2 [7] => 132 [8] => 0 )
如果您通過(guò)-
<?php $timestamp1 = time() - (23*12*30); print_r($timestamp1); print("\n"); $timestamp2 = time() + (23*12*30); print_r($timestamp2); ?>測(cè)試看看?/?
輸出結(jié)果
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 )