Coverting a number of seconds to days:hours:minutes:seconds 
Author Message
 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)


Fri, 22 Sep 2000 03:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. seconds -> hours/min/secs

2. Convert $seconds to $hours:$min:$sec

3. Changing days to seconds

4. Calculating Number of Seconds Between Two Dates

5. Converting time to number of seconds since 1.1.1970

6. PERLFUNC: time - return number of seconds since 1970

7. PERLFUNC: sleep - block for some number of seconds

8. PERLFUNC: sleep - block for some number of seconds

9. The number of seconds since 1/1/1970 ?

10. Subtracting Number of seconds from a date

11. PERLFUNC: time - return number of seconds since 1970

12. returns number of seconds since epoch for any given date

 

 
Powered by phpBB® Forum Software