Michal Checinski

Get date and time from another timezone in PowerShell

October 12, 2020 , posted under PowerShell
Get date and time from another timezone in PowerShell

Recently I stumbled upon a problem with time in PowerShell. When I ran my script on my PC, the date and time in the PowerShell script were fine. But on the remote machine

$timezone = [System.TimeZoneInfo]::FindSystemTimeZoneById("Central European Standard Time")
$now = [System.TimeZoneInfo]::ConvertTimeFromUtc((Get-Date).ToUniversalTime(), $timezone)

That way the $now variable will hold the date and time from the Central European Standard Time zone. To find out the timezone id that you want to get just type:

[system.timezoneinfo]::GetSystemTimeZones()

It will give you the list of all timezones supported by the PowerShell on a machine. Alternatively, you could find the name of the timezone with a piece of it’s id:

[system.timezoneinfo]::GetSystemTimeZones() | Where-Object {$_.id.Contains("Central European")}

Featured image by Fatos Bytyqi on Unsplash