一、time函数
time函数是返回距1970年1月1日0点到现在的秒数
#!/usr/bin/perl use 5.12.0; use warnings; use strict; my $now1 = time; print "$now1"; for(my $i=0;$i<60000000;$i++){ } my $now2 = time; print "$now2"; my $diff = $now2 - $now1; print "$diff";
返回的秒数: 1308031555 1308031559 4
二、Time::Local模块
timelocal和time功能有点类似
#!/usr/bin/perl use 5.12.0; use warnings; use strict; use Time::Local; my $now1=timelocal(localtime()); print "$now1"; for(my $i=0;$i<60000000;$i++){ } my $now2=timelocal(localtime()); print "$now2"; my $diff=$now2-$now1; print "$diff";
1308034537 1308034541 4