Perl文件::stat输出出现问题,需要显示日期

Perl文件::stat输出出现问题,需要显示日期,perl,Perl,我在获取File::stat以输出文件的最后修改日期时遇到问题。这是我目前的代码: #!/usr/bin/perl use Time::localtime; use File::stat; use warnings; use File::Find; my $dirloc = 'E:\tmp\testdir'; sub find_txt { my $F = $File::Find::name; if ( ! -d $F && $F =~ /.tar|.exe

我在获取File::stat以输出文件的最后修改日期时遇到问题。这是我目前的代码:

#!/usr/bin/perl
use Time::localtime;
use File::stat;
use warnings;
use File::Find;



my $dirloc = 'E:\tmp\testdir';

sub find_txt {
    my $F = $File::Find::name;
    if ( ! -d $F && $F =~ /.tar|.exe|.zip/ ) {  
        my @result = $F;

        foreach my $result (@result){
            my $timestamp;
            $timestamp = (stat("$result"))->[9] or die "No $_: $!";
            print "$result : $timestamp\n";

        }
    }
}


find({wanted => \&find_txt}, $dirloc);
它输出如下内容:

C:/tmp/testdir/foo/bar/test.tar:1415305933

我需要它输出(日期格式不必是列出的内容,我只想查看日期):

C:/tmp/testdir/foo/bar/test.tar:2014年7月11日

我知道它给我的输出是自大纪元以来的时间,但我认为stat应该给出日期。我做错什么了吗?谢谢


编辑:我尝试过localtime,得到了:Time::tm=ARRAY(0x245b220),不确定那里发生了什么

您可以使用
localtime
(注意:not
Time::localtime
)函数将时间戳转换为有用的内容

my $date = localtime $timestamp
这将使其成为人类可读的字符串,如2014年11月7日星期五15:33:00

或者,您可以在列表上下文中使用它将其吐入各个字段:

my($sec, $min, $hour, $day, $month, $year, $weekday, $yearOfDay, $isDST) = localtime $timestamp

如果我使用localtime,我会得到:Time::tm=ARRAY(0x245b220),我在过去尝试过localtime,但不确定为什么会这样happening@EvanMiller删除
use Time::localtime我在回答中使用的localtime函数是一个内置的Perl函数,不是来自时间模块