求解 时间转回时间戳问题

求解 时间转回时间戳问题

求解 时间转回时间戳问题
请问 我有一个时间 比如 20070301153028 就是2007年3月1号15点30分28秒 perl里有什么函数能把它变回时间戳? 1970年以来的秒数 多谢
perldoc Time::Local.
perldoc Time::Local
多谢楼上--这是我自己写.
多谢楼上
这是我自己写的函数  但是总是多出8个小时.. 真是怪了...
my $tt = time;
my $te = &get_date($tt);
sub get_date {
my $time = shift;
my($sec, $min, $hour, $day, $mon, $year, $wday, $yday, $isdst) =(localtime($time));
return sprintf "%04d%02d%02d%02d%02d%02d", '2007',$mon+1,$day,$hour,$min,$sec;
}
print "te $te\n";
my $rr = &autonomydatefromstring($te);

print "\ntt ".$tt."\n";
my $jj = $rr -$tt;
print "rr $rr\njj $jj\n";
################# autonomydatefromstring ############################
sub autonomydatefromstring($){
my $data = shift;
my $result = undef;
my %has;

$has{'Jan'} = 1;
$has{'Feb'} = 2;
$has{'Mar'} = 3;
$has{'Apr'} = 4;
$has{'May'} = 5;
$has{'Jun'} = 6;
$has{'Jul'} = 7;
$has{'Aug'} = 8;
$has{'Sep'} = 9;
$has{'Oct'} = 10;
$has{'Nov'} = 11;
$has{'Dec'} = 12;

#$data =~s/^(\s*).*?(\s*)$/$1/;
if ($data =~/^(\d\d\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)$/) {
$result = &time2s($1,$2,$3,$4,$5,$6); print "$3\n";
}elsif($data =~/^(\d\d\d\d).(\d\d).(\d\d).(\d\d).(\d\d).(\d\d)/){
$result = &time2s($1,$2,$3,$4,$5,$6);
}elsif($data =~/^(\w\w\w).(\d\d).(\d\d\d\d).(\d\d).(\d\d).(\d\d)/){
if (!defined $has{$1}){
$err = "warn month input: $1\n";
&my_catch();
}
$result = &time2s($3,$has{$1},$2,$4,$5,$6);
}elsif ($data =~/now/){
$result = time;
}else {
$err = "warn date input: $data\n";
&my_catch();
}
return $result;

}

sub time2s($$$$$$){
my $y = shift;
my $mon = shift;
my $d = shift;
my $h = shift;
my $min = shift;
my $s = shift;
my $days = &ymd_to_days($y,$mon,$d);
my $result = $days*86400+$h*3600+$min*60+$s;
return $result;

}
sub ymd_to_days($$$){
my @monthdays =(31, 28, 31, 30, 31, 30,31, 31, 30, 31, 30, 31);
my $year = shift;
my $month = shift;
my $days = shift;
my $i;
for ($i = 1;$i < $month;$i++){
$days += $monthdays[$i - 1];
}
if ($month > 2 && &isleapyear($year)){
$days++;
}
my $j;
for ($j = 1970; $j < $year;$j++){
if (&isleapyear($j)) {
$days += 366;
}else {
$days += 365;
}
}
return $days - 1;

}

sub isleapyear($){
my $y = shift;
return ((!($y % 4) && ($y % 100 ) ) || !($y % 400));
}
我们是 +8时区
要剪掉的
啥都不说了,楼上我爱你。.