If I have an ISO 8601-compliant timestamp that uses a comma as the fractional second seperator, e.g.:
$strTimestamp = '2021-08-31T23:12:11,5-05:00'
(i.e., 2021-08-31 at 23:12:11 and 0.5 seconds, UTC-5 offset)
How do I convert this to native PowerShell datetime? I've tried:
Get-Date -Date $strTimestamp
but it throws an error:
Get-Date: Cannot bind parameter 'Date'. Cannot convert value "2021-08-31T23:12:11,5-05:00" to type "System.DateTime". Error: "String '2021-08-31T23:12:11,5-05:00' was not recognized as a valid DateTime."
It's worth noting that the same timestamp with a period instead of a comma works just fine:
(Get-Date -Date '2021-08-31T23:12:11.5-05:00') | Format-List
Returns:
DisplayHint : DateTime
Date : 8/31/2021 12:00:00 AM
Day : 31
DayOfWeek : Tuesday
DayOfYear : 243
Hour : 23
Kind : Local
Millisecond : 500
Minute : 12
Month : 8
Second : 11
Ticks : 637660483315000000
TimeOfDay : 23:12:11.5000000
Year : 2021
DateTime : Tuesday, August 31, 2021 11:12:11 PM
Since the comma separator is compliant with the standard, an ideal answer would accept a comma, a period, or no separator at all.
Thanks!