📜  PHP | DirectoryIterator getATime()函数

📅  最后修改于: 2022-05-13 01:56:40.327000             🧑  作者: Mango

PHP | DirectoryIterator getATime()函数

DirectoryIterator::getATime()函数是PHP中的一个内置函数,用于获取当前 DirectoryIterator 项的最后访问时间。

句法:

int DirectoryIterator::getATime( void )

参数:此函数不接受任何参数。

返回值:此函数将上次访问文件的时间作为 Unix 时间戳返回。

下面的程序说明了PHP中的 DirectoryIterator::getATime()函数:

方案一:

valid()) {
  
    // Check for directory element
    if ($directory->isDir()) {
        $file = $directory->current();
  
        // Display the filename and last accessed time
        echo $file->getFilename() . " | ATime: "
                . $directory->getATime() . "
";     }        // Move to the next element     $directory->next(); } ?>

输出:

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

方案二:

current();
      
    // Display the key, filename and its
    // last accessed time
    echo $dir->key() . " => " . 
        $file->getFilename() . " | ATime: " .
        $dir->getATime() . "
"; } ?> 

输出:

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