时间的四舍五入问题

时间的四舍五入问题

时间的四舍五入问题
把日期计算成秒数时,采用4舍5入,遇到23点59分59秒的情况不作进位处理
例如:200706272221033
200706272223037
最后一位可进行四舍五入




   

my $.
my $timematch1 = '([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{1})';
my $timematch2 = "235959";
my $a2 = $ar1[6];
my $b2 = $ar1[7];
&match(*a2,*timematch1,*timematch2);
&match(*b2,*timematch1,*timematch2);
$ar1[6] = $a2;
$ar1[7] = $b2;

sub match{ #时间转换子程序
local (*ar,*submatch1,*submatch2) = @_;
if(length($ar) == 15 && $ar =~ m/^$submatch1$/){
if($ar =~ /$submatch2/ or (0 <= $7 && $7 <= 4)){
$ar = join("-",$1,$2,$3,$4,$5,$6);
}
elsif(5 <= $7 && $7 <= 9){
($year, $month, $day, $hh, $mm, $ss) = Add_Delta_DHMS(
$1,$2,$3,$4,$5,$6, # $ar
0,0,0,1); # 0 days, 0 hrs, 0 min, 1 sec
$ar = join("-",$year, $month, $day, $hh, $mm, $ss);
}
}
}
我自己做的,还请各位多多指教