Beefy Boxes and Bandwidth Generously Provided by pair Networks kudra
Keep It Simple, Stupid
 
PerlMonks  

time calculation

by dolavoie (Initiate)
on Feb 03, 2006 at 14:30 UTC ( [id://527787]=perlquestion: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.

dolavoie has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I need to add the following minutes: 01:45 60:00 45:25 How should I do this ? I am currently turning the minutes in seconds but I seem to be loosing some minutes

Replies are listed 'Best First'.
Re: time calculation
by rhesa (Vicar) on Feb 03, 2006 at 14:48 UTC
    What have you tried sofar?

    Converting to seconds seems like a sensible approach. You could do it like this:

    use List::Util qw/ sum /; # calculate total number of seconds $seconds = sum map { my ($m,$s) = split /:/; $m*60 + $s } qw/ 01:45 60:00 45:25 /; # or your array with times $minutes = int($seconds / 60); # integral number of minutes $seconds = $seconds % 60; # remaining seconds $new_time = sprintf "%02d:%02d", $minutes, $seconds;
Re: time calculation
by smokemachine (Hermit) on Feb 03, 2006 at 22:39 UTC
    perl -e '($sec, $min)=localtime time; printf "%.2d:%.2d", $min, $sec'
    or
    perl -e '$,=":";print reverse @ms=(localtime)[0, 1];'
Re: time calculation
by graff (Chancellor) on Feb 04, 2006 at 00:54 UTC
    Is "01:45" one minute and 45 seconds, or one hour and 45 minutes? I wonder because "60:00", if it were minutes and seconds, should probably have been "1:00:00".

    Apart from that, the next time you post a question like this, show us some code that you have tried. If all you give us is "I am currently losing some minutes", all we can say is "well, where were they when you last saw them? Have you checked all your pockets?"

    (For that matter, if you're still having trouble with this problem, you can post some code so we can help you look for those missing minutes.)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://527787]
Approved by saberworks
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.