Creating a DateTime object with a specific UTC DateTime in PowerShell
The DateTime
object itself is being created with the proper UTC time. But when PowerShell prints it out it converts it to my local culture and time zone, thus the difference.
Proof:
$UtcTime = Get-Date -Date "1970-01-01 00:00:00Z"$UtcTime.ToUniversalTime()
$utctime = New-Object DateTime 1970, 1, 1, 0, 0, 0, ([DateTimeKind]::Utc)
If you print out $utctime
, then you get:
1. januar 1970 00:00:00
Also, $utctime.Kind
is correctly set to Utc
.