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
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.