perl时间处理


#!/usr/bin/perl

use Time::Local;

my $time1="Thu Jun 14 10:03:53 CST 2018";

my $time2="Thu Jun 14 03:07:09 2018";


sub get_mon

{

($p1)[email protected]_;

my $mon=0;

my $num=-1;

my $monstr="Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec";

my @monlist= split / /,$monstr;

foreach $m (@monlist){

$num=$num+1;

if ($p1 eq $m){

$mon=$num;

}

}

return $mon;

}

   

sub get_istat_time

{

my $TIME1 = "";

   ($p)[email protected]_;

   #my $time1="Thu Jun 14 10:03:53 CST 2018";

   #my $time2="Thu Jun 14 03:07:09 2018";

   if ($p=~/(\w{3})(\s+)(\w{3})(\s+)(\d{2})(\s+)(\d{2})(\:)(\d{2})(\:)(\d{2})(\s+)(\d{4})(.*)/)

      {

        #my $p1="$1";

        #printf "$1,$3,$5,$7,$9,$11,$13,$15\n";

$sec=$11;

$min=$9;

$hour=$7;

$day=$5;

$mon=get_mon $3;

$year=$13;

#printf "$sec,$min,$hour,$day,$mon,$year\n";

      }

elsif ($p=~/(\w{3})(\s+)(\w{3})(\s+)(\d{2})(\s+)(\d{2})(\:)(\d{2})(\:)(\d{2})(\s+)(\w{3})(\s+)(\d{4})(.*)/)

      {

        #my $p1="$1";

        #printf "$1,$15\n";

$sec=$11;

$min=$9;

$hour=$7;

$day=$5;

$mon=get_mon $3;

$year=$15;

#printf "$sec,$year\n";

      }

  

   $TIME1 = timelocal($sec,$year);

   

   return $TIME1;

}


sub help()

{

  print "usage:\n";

  print "get_time \"Thu Jun 14 10:03:53 CST 2018\"\n";

  print "get_time \"Thu Jun 14 03:07:09 2018\"\n";

  exit 1;

}



sub main()

{

        if(@ARGV<1)

  {

          help();

  }

       

printf(get_istat_time($ARGV[0]));

printf("\n");    

}


main

相关文章

1. 如何去重 #!/usr/bin/perl use strict; my %hash; while(...
最近写了一个perl脚本,实现的功能是将表格中其中两列的数据...
表的数据字典格式如下:如果手动写MySQL建表语句,确认麻烦,...
巡检类工作经常会出具日报,最近在原有日报的基础上又新增了...
在实际生产环境中,常常需要从后台日志中截取报文,报文的形...
最近写的一个perl程序,通过关键词匹配统计其出现的频率,让...