
Coverting a number of seconds to days:hours:minutes:seconds
Quote:
> Hello
> Perhaps I have been staring at this too long.
> I am trying to convert an *amount* of seconds to
> days:hours:minutes:seconds format
Why not:
#!/usr/bin/perl -w
require 5.004; # For use constant
use strict;
use constant SEC_PER_DAY => 60 * 60 * 24; # This might be less efficient
use constant SEC_PER_HOUR => 60 * 60; # than just using the constants
use constant SEC_PER_MIN => 60; # but you were ready to read
# a whole module for it so I
# thought it'd be fine
# You may want to substitute your own program here
print join(':', sec_to_days(17682)), "\n";
sub sec_to_days($) {
my $sec = shift;
use integer;
$sec %= SEC_PER_DAY;
$sec %= SEC_PER_HOUR;
$sec %= SEC_PER_MIN;
Quote:
}
> I think I've read up on all the Time:: and Date:: modules but none
> seems to really be the thing.
Here it seems simpler to just roll your own. (Or my own--but no guarantees)