第一种- $d = @(
- '00:04:30'
- '00:05:25'
- '00:05:20'
- )
- $h = $m = $s = 0
- $d | foreach {
- $arr = $_ -split ':'
- $s += [int]$arr[2]
- $m += [System.Math]::Floor($s / 60); $s = $s % 60
- $m += [int]$arr[1]
- $h += [System.Math]::Floor($m / 60); $m = $m % 60
- $h += [int]$arr[0]
- }
- '{0}:{1}:{2}' -f $h,$m,$s
复制代码 第二种- $d = @(
- '00:04:30'
- '00:05:25'
- '00:05:20'
- )
- $t = [timespan]::Zero
- $d | foreach { $t += [timespan]$_ }
- '{0}:{1}:{2}' -f $t.Hours,$t.Minutes,$t.Seconds
复制代码
|