Thread Zeitangaben addieren: h:min + h:min = ? (8 answers)
Opened by MartinR at 2006-11-17 15:06

bloonix
 2006-11-18 20:32
#71833 #71833
User since
2005-12-17
1615 Artikel
HausmeisterIn
[Homepage]
user image
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
use strict;
use warnings;

my @times = (
'13:45:23',
'14:12:43',
);

my $d = 0; # day
my $h = 0; # hour
my $m = 0; # min
my $s = 0; # sec

foreach my $time (@times) {
  my ($hour, $min, $sec) = split /:/, $time;
  $s += $hour * 3600 + $min * 60 + $sec;
}

$s >= 86400 and $d = sprintf('%i',$s / 86400) and $s = $s % 86400;
$s >= 3600  and $h = sprintf('%i',$s / 3600)  and $s = $s % 3600;
$s >= 60    and $m = sprintf('%i',$s / 60)    and $s = $s % 60;

print "${d}d ${h}h ${m}m ${s}s\n";


1d 3h 58m 6s\n\n

<!--EDIT|opi|1163874815-->
What is a good module? That's hard to say.
What is good code? That's also hard to say.
One man's Thing of Beauty is another's man's Evil Hack.

View full thread Zeitangaben addieren: h:min + h:min = ?