使用Perl在Apache日志中解析时间

使用Perl在Apache日志中解析时间,apache,perl,datetime,Apache,Perl,Datetime,如何用Perl解析Apache日志中的日期/时间 Apache日志中的日期/时间示例: [2014年5月20日星期二13:23:17]输出是自新纪元以来的秒数 use Time::Piece; my $str = "[Tue May 20 13:23:17 2014]"; my $t = Time::Piece->strptime($str, "[%a %B %d %H:%M:%S %Y]"); print $t->epoch, "\n"; # print $t, "\n"; c

如何用Perl解析Apache日志中的日期/时间

Apache日志中的日期/时间示例:


[2014年5月20日星期二13:23:17]

输出是自新纪元以来的秒数

use Time::Piece;

my $str = "[Tue May 20 13:23:17 2014]";

my $t = Time::Piece->strptime($str, "[%a %B %d %H:%M:%S %Y]");
print $t->epoch, "\n";
# print $t, "\n"; check if correctly parsed