如何使用PowerShell将”PT5H”转换为刻度?

huangapple go评论69阅读模式
英文:

How to convert "PT5H" to ticks using powershell?

问题

我正在尝试使用PowerShell将“PT5H”转换为滴答格式,但遇到以下错误:

System.Management.Automation.ParameterBindingArgumentTransformationException:无法处理参数“SuppressionDuration”的参数转换。无法将值“PT5H”转换为类型“System.TimeSpan”。错误:“字符串未被识别为有效的TimeSpan。”

有人可以帮助我将“PT5H”(字符串)转换为滴答吗?

英文:

I'm trying to convert "PT5H" to ticks format using powershell. But facing below error:

System.Management.Automation.ParameterBindingArgumentTransformationException: Cannot process argument transformation on parameter 'SuppressionDuration'. Cannot convert value "PT5H" to type "System.TimeSpan". Error: "String was not recognized as a valid TimeSpan."

Can anyone help me out in converting "PT5H"(String) to ticks ?

答案1

得分: 3

你可以使用XmlConvert.ToTimeSpan()方法来解析ISO8601持续时间字符串:

$duration = [System.Xml.XmlConvert]::ToTimeSpan('PT5H')
Command-Name -SuppressionDuration $duration
英文:

You can use the XmlConvert.ToTimeSpan() method to parse ISO8601 duration strings:

$duration = [System.Xml.XmlConvert]::ToTimeSpan('PT5H')
Command-Name -SuppressionDuration $duration

huangapple
  • 本文由 发表于 2023年1月9日 17:33:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/75055343.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定