When I'm trying to sort mails I got, there is only date in RFC3501, such as 'Thu
, 15 Mar 2012 15
:46
:10
+0800'. I don't want to impor too many modules, so I write this. Just a prototype. And need to handle the timezone and time with only single digit.
- #!/usr/bin/perl -w
- #
- sub ConvertRFC3501toUnixTime{
- my $input = shift;
- #Thu, 15 Mar 2012 15:46:10 +0800
- my %months = ("Jan" => 1,"Feb" => 2,"Mar" => 3,"Apr" => 4,"May" => 5,"Jun" => 6,"Jul" => 7,"Aug" => 8,"Sep" => 9,"Oct" => 10,"Nov" => 11,"Dec" => 12);
- my($day,$mon,$year,$hour,$min,$sec) = $input =~ /(\d{2}) (\w{3}) (\d{4}) (\d{2}):(\d{2}):(\d{2})/;
-
- my $time = $sec.$min.$hour.$day.($months{$mon}-1).($year - 1900);
- return $time;
- }
- my $str = 'Thu, 28 Mar 2012 15:46:10 +0800';
- print localtime;
- print "\n";
- print ConvertRFC3501toUnixTime($str);
阅读(688) | 评论(0) | 转发(0) |