Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

time calculation

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

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 19: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 graff (Chancellor) on Feb 04, 2006 at 05: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.)

Re: time calculation
by smokemachine (Hermit) on Feb 04, 2006 at 03:39 UTC
    perl -e '($sec, $min)=localtime time; printf "%.2d:%.2d", $min, $sec'
    or
    perl -e '$,=":";print reverse @ms=(localtime)[0, 1];'

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://527787]
Approved by saberworks
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (8)
As of 2020-05-26 13:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If programming languages were movie genres, Perl would be:















    Results (150 votes). Check out past polls.

    Notices?