当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


PHP DirectoryIterator getMTime()用法及代码示例


DirectoryIterator::getMTime()函数是PHP中的内置函数,用于返回当前DirectoryIterator项的最后修改时间。

用法:

int DirectoryIterator::getMTime( void )

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


返回值:此函数以Unix时间戳格式返回文件的最后修改时间。

以下示例程序旨在说明PHP中的DirectoryIterator::getMTime()函数:

示例1:

<?php 
  
// Create a directory Iterator 
$directory = new DirectoryIterator(dirname(__FILE__)); 
  
// Loop runs while directory is valid 
while ($directory->valid()) { 
  
    // Check it is directory or not 
    if ($directory->isDir()) { 
  
        $file = $directory->current(); 
  
        // Displaty the filename and last modified time 
        echo $file->getFilename() . " | MTime: "
                . $directory->getMTime() . "<br>"; 
    } 
  
    // Move to the next element of directory 
    $directory->next(); 
} 
?>

输出:

. | MTime: 1574616421
.. | MTime: 1574540515
dashboard | MTime: 1574350724
img | MTime: 1574350724
webalizer | MTime: 1574350718
xampp | MTime: 1574350724

示例2:

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

输出:

0 => . | MTime: 1574616421
1 => .. | MTime: 1574540515
2 => applications.html | MTime: 1566914572
3 => bitnami.css | MTime: 1566914572
4 => dashboard | MTime: 1574350724
5 => favicon.ico | MTime: 1437060752
6 => geeks.PNG | MTime: 1573806007
7 => gfg.php | MTime: 1574653649
8 => img | MTime: 1574350724
9 => index.php | MTime: 1437060752
10 => webalizer | MTime: 1574350718
11 => xampp | MTime: 1574350724

注意:此函数的输出取决于服务器文件夹的内容。

参考: https://www.php.net/manual/en/directoryiterator.getmtime.php



相关用法


注:本文由纯净天空筛选整理自jit_t大神的英文原创作品 PHP | DirectoryIterator getMTime() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。