I think your code is working fine. In between the two calls to
getMeanTime() add a
sleep(2); in there and you will find that you will get a difference in seconds instead of no difference at all.That is:
#!/usr/bin/perl
use strict;
use warnings;
use Date::Calc qw(Delta_YMDHMS);
my ($day1,$month1,$year1,$hour1,$min1,$sec1) = &getMeanTime;
sleep(2);
my ($day2,$month2,$year2,$hour2,$min2,$sec2) = &getMeanTime;
my ($D_y,$D_m,$D_d, $Dh,$Dm,$Ds) = Delta_YMDHMS(
$year1,$month1,$day1, $hour1,$min1,$sec1,
$year2,$month2,$day2, $hour2,$min2,$sec2);
print sprintf("%02d", $D_d).'/'
. sprintf("%02d", $D_m).'/'
. sprintf("%04d", $D_y).' '
. sprintf("%02d", $Dh) . ':'
. sprintf("%02d", $Dm) . ':'
. sprintf("%02d", $Ds);
sub getMeanTime {
my $time = time;
my ($Second, $Minute, $Hour, $Day, $Month, $Year, $WeekDay, $DayOfYe
+ar, $IsDST) = gmtime($time);
$Year+=1900; $Month+=1;
return $Day,$Month,$Year,$Hour,$Minute,$Second;
} #getMeanTime
__END__
00/00/0000 00:00:02
-enlil