# perldoc > timestamp

## Found in /usr/share/perl/5.38/pod/perlfaq5.pod
  How do I get a file's timestamp in perl?
    If you want to retrieve the time at which the file was last read,
    written, or had its meta-data (owner, etc) changed, you use the -A, -M,
    or -C file test operations as documented in perlfunc. These retrieve the
    age of the file (measured against the start-time of your program) in
    days as a floating point number. Some platforms may not have all of
    these times. See perlport for details. To retrieve the "raw" time in
    seconds since the epoch, you would call the stat function, then use
### localtime
    human-readable form.

    Here's an example:

        my $write_secs = (stat($file))[9];
        printf "file %s updated at %s\n", $file,
            scalar localtime($write_secs);

    If you prefer something more legible, use the [File::stat](https://www.chedong.com/phpMan.php/perldoc/File%3A%3Astat/markdown) module (part of
    the standard distribution in version 5.004 and later):

        # error checking left as an exercise for reader.
        use [File::stat](https://www.chedong.com/phpMan.php/perldoc/File%3A%3Astat/markdown);
        use [Time::localtime](https://www.chedong.com/phpMan.php/perldoc/Time%3A%3Alocaltime/markdown);
        my $date_string = ctime(stat($file)->mtime);
        print "file $file updated at $date_string\n";

    The [POSIX::strftime](https://www.chedong.com/phpMan.php/perldoc/POSIX%3A%3Astrftime/markdown)() approach has the benefit of being, in theory,
    independent of the current locale. See perllocale for details.

  How do I set a file's timestamp in perl?
    You use the utime() function documented in "utime" in perlfunc. By way
    of example, here's a little program that copies the read and write times
    from its first argument to all the rest of them.

        if (@ARGV < 2) {
            die "usage: cptimes timestamp_file other_files ...\n";
        }
        my $timestamp = shift;
        my($atime, $mtime) = (stat($timestamp))[8,9];
        utime $atime, $mtime, @ARGV;

    Error checking is, as usual, left as an exercise for the reader.

    The perldoc for utime also has an example that has the same effect as
### touch

    Certain file systems have a limited ability to store the times on a file
    at the expected level of precision. For example, the FAT and HPFS
    filesystem are unable to create dates on files with a finer granularity
    than two seconds. This is a limitation of the filesystems, not of
### utime

