in reply to How to find Date and Time difference?
Also note that instead of gmtime, you can (just for ease of the array usage and for Date::Clac consistency) use Today_and_Now():use Date::Calc qw(Delta_YMDHMS); # @d arrays are (y,mon,d,h,min,s) my @dt1 = getMeanTime(); sleep(2); my @dt2 = getMeanTime(); my @dt = Delta_YMDHMS( @dt1, @dt2 ); printf "%02d/%02d/%04d %02d:$02d:$02d", @dt[2,1,0, 3..5]; sub getMeanTime { my @t = gmtime; return ( $t[5]+1900, $t[4]+1, $t[3], @t[2..0] ); # (y, mon, day, h, + min, s) }
use Date::Calc qw(Delta_YMDHMS Today_and_Now); # @d arrays are (y,mon,d,h,min,s) my @dt1 = Today_and_Now(); sleep(2); my @dt2 = Today_and_Now(); my @dt = Delta_YMDHMS( @dt1, @dt2 ); printf "%02d/%02d/%04d %02d:$02d:$02d", @dt[2,1,0, 3..5];
|
|---|