我正在寻找一种将军事时间字符串(“22:12:02”)转换为日期时间对象的方法。
下面是代码示例:
$TimePrevious = $Null
[array]$TimeArray = "22:12:02.000", "22:12:03.000", "23:12:02.000"
$TimeArray | ForEach-Object {
$TimeCurrent = $_.Substring(0,8)
$TimeDifference = [datetime]$TimeCurrent.TimeOfDay - [datetime]$TimePrevious.TimeOfDay
If ($TimeDifference.Second -lt "10") {Write-Host "$_ is less than 10 seconds"}
$TimePrevious = $_
}
错误显示“无法将“System.TimeSpan”类型的“22:12:02”值转换为“System.DateTime”类型