Convert seconds to days, hours, minutes using Perl

前端 未结 1 1699
半阙折子戏
半阙折子戏 2021-01-13 09:07

I would like to take control of the output generated in seconds using perl. I would like to show the time (in seconds) in the form of days, hours,

相关标签:
1条回答
  • 2021-01-13 09:43

    You could use the Time::Piece and Time::Seconds modules, which will do all of this for you

    In this program I have simply added pi days onto the current date and time to get a representative duration. You will, of course, use an actual time

    use strict;
    use warnings;
    
    use Time::Piece;
    use Time::Seconds qw/ ONE_DAY /;
    
    my $start = localtime;
    my $end = $start + int(355/113 * ONE_DAY);
    
    my $duration = ($end - $start)->pretty;
    print "Total Execution time: $duration\n";
    

    output

    Total Execution time: 3 days, 3 hours, 23 minutes, 53 seconds
    
    0 讨论(0)
提交回复
热议问题