2

在 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 中检查文件时间戳?

4

1 回答 1

4

Perl 5 中的文件测试运算符,在 Perl 6 中是来自角色的方法(例如 .modified.accessed.changed)。IO::FileTestable

例如:

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
于 2015-05-15T16:34:53.990 回答