When ConvertFrom-JSON guesses something in the input data can be converted to a DateTime, it (silently) does so.
But the conversion doesn't correctly interprets some strings.
Steps to reproduce
I'm running this on a system that's on UTC+2 (CEST).
Write-Host("PowerShell version: " + $PSVersionTable.PSVersion.ToString())
$date = "2020-09-07T09:44:13.769Z"
Write-Host ("Original string: " + $date)
Write-Host("Cast to Datetime: " + [datetime] $date)
$json = ('[{"start":"' + $date + '"}]')
Write-Host("JSON data: " + $json)
$data = $json | ConvertFrom-Json
Write-Host($data[0].start.GetType().Name + " resulting from ConvertFrom-JSON: " + $data[0].start)
Expected behavior
PowerShell version: 7.0.3
Original string: 2020-09-07T09:44:13.769Z
Cast to Datetime: 09/07/2020 11:44:13
JSON data: [{"start":"2020-09-07T09:44:13.769Z"}]
DateTime resulting from ConvertFrom-JSON: 09/07/2020 11:44:13
Actual behavior
PowerShell version: 7.0.3
Original string: 2020-09-07T09:44:13.769Z
Cast to Datetime: 09/07/2020 11:44:13
JSON data: [{"start":"2020-09-07T09:44:13.769Z"}]
DateTime resulting from ConvertFrom-JSON: 09/07/2020 09:44:13
Environment data
Name Value
---- -----
PSVersion 7.0.3
PSEdition Core
GitCommitId 7.0.3
OS Microsoft Windows 10.0.17763
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
The same issue is still present in 7.1.0-preview.6.
When
ConvertFrom-JSONguesses something in the input data can be converted to aDateTime, it (silently) does so.But the conversion doesn't correctly interprets some strings.
Steps to reproduce
I'm running this on a system that's on UTC+2 (CEST).
Expected behavior
Actual behavior
Environment data
The same issue is still present in 7.1.0-preview.6.