LLI Wiki — My Digital Knowledge Base

Show local time and convert it to UTC in PowerShell

Show the date and UTC offset with Get-Date -UFormat, and convert a date to UTC with ToUniversalTime().

PowerShell can display the current local time with its offset from UTC, and convert a date to universal time (UTC).

Show the local time with its UTC offset

Get-Date -UFormat accepts the same format specifiers as the Unix date command. %Z displays the offset from UTC.

Get-Date -UFormat "%A %m/%d/%Y %R %Z"

Example output on a system with a French locale, in the UTC+02 zone: jeudi 08/20/2020 18:19 +02

Convert a date to UTC

The ToUniversalTime() method of the DateTime object returns the same moment expressed in UTC.

$Time = Get-Date
$Time.ToUniversalTime()
Mastodon LLIMastodon SocialFosstodon