September 16th, 2016

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

Doctor Scripto
Scripter

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

Author

The "Scripting Guys" is a historical title passed from scripter to scripter. The current revision has morphed into our good friend Doctor Scripto who has been with us since the very beginning.

0 comments

Discussion are closed.