我正在尝试将日期格式从"PT10H24M30S"
转换为"10:24:30"
。
我创建了以下函数:
function PTTime([string] $time){
$pattern = "(\d{2})+"
$matches = $time | Select-String -Pattern $pattern -AllMatches
$newFormat += $matches.Matches | ForEach {$_.Value}
$newFormat = $newFormat -Replace " ",":"
return $newFormat
}
但是,如果我调用该函数,则会得到输出
10 24 30
或
10
24
30
但是,另一方面,如果我一次在命令行上执行功能命令1,则在打印$newFormat
"10:24:30"
时得到正确的输出