how to find the file is created o开发者_JAVA百科r updated current date/day
You could use the -M
function to see if the file has been modified in the last day:
if(-M FH < 1) {
# file was modified less than one day ago
}
You can also test for time since the inode was changed with -C
, which is often (but not always) when the file was created (see here for filesystem compatibility issues).
See here for some examples of the various filetests.
Assuming that you want day and date of the file when it was last modified, you can try like this
use strict;
use warning;
use File::stat;
use Time::localtime;
my $st = stat($file) or die "No $file: $!";
my $datetime_string = ctime($st->mtime);
print "file $file was updated at $datetime_string\n";
Show on File::Stat. You can use DateTime to init the timestamp with local time zone.
精彩评论