PowerShell: How to Use Get-Date and Display Timezone


You can use the following basic syntax to use Get-Date and display the current timezone in PowerShell:

$current = Get-Date
$tz = [Regex]::Replace([System.TimeZoneInfo]::Local.StandardName, '([A-Z])\w+\s*', '$1')

#display current date and time with timezone
$current, $tz -join " "

Here is how this example works:

  • The $current variable contains the current date and time.
  • The $tz variable contains the abbreviated timezone name.
  • Then, we use the -join operator to concatenate these two variables together with a space in between them.

The following example shows how to use this syntax in practice.

Example: Use Get-Date and Display Timezone in PowerShell

Suppose that our computer is in the Eastern Standard Timezone (EST).

We can confirm this by using the following syntax in PowerShell:

[System.TimeZoneInfo]::Local.StandardName

The following screenshot shows how to use this syntax in practice:

We can use the following syntax to display the current date and time with the abbreviated timezone initials shown afterwards:

$current = Get-Date
$tz = [Regex]::Replace([System.TimeZoneInfo]::Local.StandardName, '([A-Z])\w+\s*', '$1')

#display current date and time with timezone
$current, $tz -join " "

The following screenshot shows how to use this syntax in practice:

PowerShell Get-Date timezone

The output displays the current date and time along with the timezone:

  • 3/5/2024 8:26:22 AM EST

Note that we used [Regex] along with the Replace() method to extract only the first initials from each word in the timezone.

If you would instead like to display the full timezone name with the current date and time, you can use the following syntax to do so:

$current = Get-Date
$tz = [System.TimeZoneInfo]::Local.StandardName

#display current date and time with timezone
$current, $tz -join " "

The following screenshot shows how to use this syntax in practice:

PowerShell display full timezone name

The output displays the current date and time along with the timezone:

  • 3/5/2024 8:26:22 AM Eastern Standard Time

Feel free to use whichever method you prefer.

Related Tutorials

The following tutorials explain how to perform other common tasks in PowerShell:

How to Compare Dates in PowerShell
How to Format a DateTime in PowerShell
How to Calculate Date Difference in PowerShell

Leave a Reply