在Perl 5中,您可以使用stat
来获取文件的访问,修改和更改时间戳。
例如:
my $filename = "sample.txt";
my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
$atime,$mtime,$ctime,$blksize,$blocks)
= stat($filename)
print "File '$filename' was last accessed $atime seconds since the epoch.\n";
结果是:
File 'sample.txt' was last accessed 1431707004 seconds since the epoch.
如何在Perl 6中检查文件时间戳?
答案 0 :(得分:4)
Perl 6中的file test operators from Perl 5是来自IO::FileTestable
role的方法(例如.modified
,.accessed
和.changed
)。
例如:
my $filename = "sample.txt";
my $seconds_since_epoch = $filename.IO.accessed;
my $readable_timestamp = DateTime.new($filename.IO.accessed);
say "File '$filename' was last accessed at '$readable_timestamp', which is {$seconds_since_epoch.Num} seconds since the epoch";
在我的情况下,给了:
File 'sample.txt' was last accessed at '2015-05-15T16:22:49Z', which is 1431707004 seconds since the epoch