當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


PHP DirectoryIterator getATime()用法及代碼示例


DirectoryIterator::getATime()函數是PHP中的內置函數,用於獲取當前DirectoryIterator項的最後訪問時間。

用法:

int DirectoryIterator::getATime( void )

參數:該函數不接受任何參數。


返回值:此函數以Unix時間戳記返回上次訪問文件的時間。

以下示例程序旨在說明PHP中的DirectoryIterator::getATime()函數:

示例1:

<?php 
  
// Create a directory Iterator 
$directory = new DirectoryIterator(dirname(__FILE__)); 
  
// Loop runs while directory is valid 
while ($directory->valid()) { 
  
    // Check for directory element 
    if ($directory->isDir()) { 
        $file = $directory->current(); 
  
        // Display the filename and last accessed time 
        echo $file->getFilename() . " | ATime: "
                . $directory->getATime() . "<br>"; 
    } 
  
    // Move to the next element 
    $directory->next(); 
} 
?>

輸出:

. | ATime: 1574654324
.. | ATime: 1574540515
dashboard | ATime: 1574350724
img | ATime: 1574350724
webalizer | ATime: 1574350718
xampp | ATime: 1574350724

示例2:

<?php 
  
// Create a directory Iterator 
$directory = new DirectoryIterator(dirname(__FILE__)); 
  
// Loop runs for each element of directory 
foreach($directory as $dir) { 
      
    $file = $directory->current(); 
      
    // Display the key, filename and its 
    // last accessed time 
    echo $dir->key() . " => " .  
        $file->getFilename() . " | ATime: " . 
        $dir->getATime() . "<br>"; 
} 
?> 

輸出:

0 => . | ATime: 1574654324
1 => .. | ATime: 1574540515
2 => applications.html | ATime: 1574350724
3 => bitnami.css | ATime: 1574350724
4 => dashboard | ATime: 1574350724
5 => favicon.ico | ATime: 1574350724
6 => geeks.PNG | ATime: 1574478578
7 => gfg.php | ATime: 1574654749
8 => img | ATime: 1574350724
9 => index.php | ATime: 1574350723
10 => Sublime Text Build 3211 x64 Setup.exe | ATime: 1574654324
11 => webalizer | ATime: 1574350718
12 => xampp | ATime: 1574350724

注意:此函數的輸出取決於服務器文件夾的內容。

參考: https://www.php.net/manual/en/directoryiterator.getatime.php



相關用法


注:本文由純淨天空篩選整理自jit_t大神的英文原創作品 PHP | DirectoryIterator getATime() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。