Timestamp format

Igo*_*gor 1 perl timestamp

ALL,

I'm about to parse the log file file which has following format:

2019-09-06T16:06:36+00:00 some_text
Run Code Online (Sandbox Code Playgroud)

Now what I'm curious about is to how to handle the numbers after the + sign. I can split the line by the " " character to get the timestamp, and then split the timestamp by the T, but will date/time functions in Perl will understand the 16:06:36+00:00 time? I will need to pass it to timelocal() to get an epoch time.

TIA!

Dav*_*idO 5

冒号是多余的,并且妨碍了您的解析。一段时间以前,Python Bug跟踪器中已有关于使用冒号解析时区偏移的讨论,但从未真正解决过。最简单的解决方案是摆脱它:

use Time::Piece; # A core Perl module.

my $entry = '2019-09-06T16:06:36+00:00 some_text';

my ($timestamp, $text) = split(/\s+/, $entry, 2);
$timestamp =~ s/:(\d+)$/$1/;

my $t = Time::Piece->strptime($timestamp, "%Y-%m-%dT%T%z");
Run Code Online (Sandbox Code Playgroud)

在此示例中,我们分割了第一个空格以隔离日期戳,然后替换掉最后一个冒号。因此$timestamp现在将包含:

2019-09-06T16:06:36+0000
Run Code Online (Sandbox Code Playgroud)

... strptime如果有适当的格式字符串,这是可以理解的时间戳。