Quantcast
Channel: Scripting Blog
Viewing all articles
Browse latest Browse all 2129

PowerTip: Use PowerShell to retrieve the date and time of the given time zone ID

$
0
0

Summary: Use PowerShell to pull out specify TimeZone data from an object.

Hey, Scripting Guy! Question I have data retrieved from an external source that contains different time zone IDs like W. Europe Standard Time, AUS Eastern Standard Time, etc. How can I get the current date time value of it by using PowerShell?

Hey, Scripting Guy! Answer In PowerShell, use [System.TimeZone] and invoke the ConvertTimeBySystemZoneID static method, which returns the date-time value of the given time zone!In PowerShell, use [System.TimeZone] and invoke the ConvertTimeBySystemZoneID static method, which returns the date-time value of the given time zone!

For example, you need to know the current date and time of the AUS Eastern Standard Time.

[System.TimeZoneInfo]::ConvertTimeBySystemTimeZoneId([DateTime]::Now,"AUS Eastern Standard Time")

Note: This works only if the given time zone is available on your local system. Use [System.TimeZoneInfo]::GetSystemTimeZones() to get the sorted collection of all the time zones about which information is available on the local system.

The Doctor


Viewing all articles
Browse latest Browse all 2129

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>