newbie01.perl has asked for the wisdom of the Perl Monks concerning the following question:
Hi all,
Need some help please on doing date/time arithmetic. Basically I have a script where I save the starttime and endtime using time(). And at the end of the run, I do a endtime - starttime to get the difference of how long the script took to run which I believe is in seconds.
Question is if there is any way of converting the result so that it can be displayed in x-days, x-hours, x-mins, x-seconds instead of second?
At the moment, am thinking of writing some sort of function to convert the seconds to hours, minute, seconds but before I go to that length, I am wishfully thinking that maybe someone had already come across the same requirement that am looking for. Any advise will be very much appreciated.
Excerpt of the Perl script as below. Note that am very restricted to what modules I have available and cannot install additional Date/Time modules that I've found very useful. At the moment, am only allowed Time::Local.
Any response or suggestions will be very much appreaciated. Thanks in advance.
use strict; use POSIX; use File::Basename; use Time::Local; ...... ...... my $start_time = scalar localtime; my $start = time(); ...... ...... my $end_time = scalar localtime; my $end = time(); #my $end_timelocal = timelocal($sec, $min, $hour, $mday, $mon, $year); print "end_time ==> $end_time" . "\n"; #print "end_timelocal ==> $end_timelocal" . "\n"; my $diff = $end - $start;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Date/Time Arithmetic
by Ratazong (Monsignor) on Nov 27, 2009 at 10:38 UTC | |
|
Re: Date/Time Arithmetic
by Anonymous Monk on Nov 27, 2009 at 10:39 UTC | |
|
Re: Date/Time Arithmetic
by gmargo (Hermit) on Nov 27, 2009 at 14:52 UTC | |
|
Re: Date/Time Arithmetic
by GrandFather (Saint) on Nov 27, 2009 at 21:31 UTC |