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

时间:2014-05-22 14:49:33

标签: apache perl datetime

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

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

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

1 个答案:

答案 0 :(得分:2)

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

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