#!/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
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。