Saturday, June 13, 2026
HomeLanguagesPHP | DirectoryIterator getATime() Function

PHP | DirectoryIterator getATime() Function

The DirectoryIterator::getATime() function is an inbuilt function in PHP which is used to get the last access time of the current DirectoryIterator item.

Syntax:

int DirectoryIterator::getATime( void )

Parameters: This function does not accept any parameters.

Return Value: This function returns the time of last accessed file as a Unix timestamp.

Below programs illustrate the DirectoryIterator::getATime() function in PHP:

Program 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();
}
?>


Output:

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

Program 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>";
}
?> 


Output:

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 => neveropen.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

Note: The output of this function depends on the content of server folder.

Reference: https://www.php.net/manual/en/directoryiterator.getatime.php

RELATED ARTICLES

Most Popular

Dominic
32515 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6897 POSTS0 COMMENTS
Nicole Veronica
12013 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6964 POSTS0 COMMENTS