{"id":81916,"date":"2017-02-01T11:59:56","date_gmt":"2017-02-01T19:59:56","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/?p=81916"},"modified":"2019-02-18T09:10:13","modified_gmt":"2019-02-18T16:10:13","slug":"powertip-convert-from-utc-to-my-local-time-zone","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/powertip-convert-from-utc-to-my-local-time-zone\/","title":{"rendered":"PowerTip: Convert from UTC to my local time zone"},"content":{"rendered":"<p><strong>Summary<\/strong>: Cloud and Datacenter Management MVP, Thomas Rayner, shows how write a function to convert from UTC to your local time zone.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" alt=\"Hey, Scripting Guy! Question\" \/> I have a time that I\u2019d like to convert from UTC to my local time zone. How can I do this?<\/p>\n<p style=\"padding-left: 30px\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" alt=\"Hey, Scripting Guy! Answer\" \/> You can write your own function to do this, and use the [<a target=\"_blank\" href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/system.timezoneinfo(v=vs.110).aspx\">System.TimeZoneInfo<\/a>] .NET class and associated methods to make this conversion easily. Here is an example:<\/p>\n<p style=\"padding-left: 90px\"><code>function Convert-UTCtoLocal<\/code><\/p>\n<p style=\"padding-left: 90px\"><code>{\nparam(\n[parameter(Mandatory=$true)]\n[String] $UTCTime\n)<\/code><\/p>\n<p style=\"padding-left: 90px\"><code>$strCurrentTimeZone = (Get-WmiObject win32_timezone).StandardName\n$TZ = [System.TimeZoneInfo]::FindSystemTimeZoneById($strCurrentTimeZone)\n$LocalTime = [System.TimeZoneInfo]::ConvertTimeFromUtc($UTCTime, $TZ)\n}<\/code><\/p>\n<p style=\"padding-left: 30px\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/7610.Dr.ScriptoForTips.jpg\" alt=\"The Doctor\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Cloud and Datacenter Management MVP, Thomas Rayner, shows how write a function to convert from UTC to your local time zone. I have a time that I\u2019d like to convert from UTC to my local time zone. How can I do this? You can write your own function to do this, and use the [&hellip;]<\/p>\n","protected":false},"author":596,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[568,639,641],"tags":[56,356,652,45],"class_list":["post-81916","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-hey-scripting-guy","category-powertip","category-windows-powershell","tag-guest-blogger","tag-powertip","tag-thomas-rayner","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Cloud and Datacenter Management MVP, Thomas Rayner, shows how write a function to convert from UTC to your local time zone. I have a time that I\u2019d like to convert from UTC to my local time zone. How can I do this? You can write your own function to do this, and use the [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/81916","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/596"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=81916"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/81916\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=81916"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=81916"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=81916"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}