PowerTip: Convert from UTC to my local time zone

Doctor Scripto

Dr Scripto

Summary: Cloud and Datacenter Management MVP, Thomas Rayner, shows how write a function to convert from UTC to your local time zone.

Hey, Scripting Guy! Question I have a time that I’d like to convert from UTC to my local time zone. How can I do this?

Hey, Scripting Guy! Answer You can write your own function to do this, and use the [System.TimeZoneInfo] .NET class and associated methods to make this conversion easily. Here is an example:

function Convert-UTCtoLocal

[String] $UTCTime

$strCurrentTimeZone = (Get-WmiObject win32_timezone).StandardName
$TZ = [System.TimeZoneInfo]::FindSystemTimeZoneById($strCurrentTimeZone)
$LocalTime = [System.TimeZoneInfo]::ConvertTimeFromUtc($UTCTime, $TZ)

The Doctor

Doctor Scripto
Dr Scripto

Scripter, PowerShell, vbScript, BAT, CMD

Follow Dr Scripto   


    Leave a comment