[Solved] Converting numbers to K/M/G/T and days/hours/min?


This was discussed on Stackoverflow using Time::Piece. One of the answers comes close to calculating days hours minutes. From what I’ve read about this question before, I think you can easily code it up like this:

sub dhms {
    my $seconds = shift;
    my $days = int $seconds / 86400;
    $seconds %= 86400;
    my $hours = int $seconds / 3600;
    $seconds %= 3600;
    my $mins = int $seconds / 60;
    my $secs = $seconds % 60;
    return $days, $hours, $mins, $secs;
}

Update: daxim’s answer using DateTime::Format::Duration does this as well

solved Converting numbers to K/M/G/T and days/hours/min?