Get-Date ([datetime]::UtcNow) -UFormat %H
Up to PowerShell 7.0, Get-Date
doesn't directly support formatting the current time based on its UTC value: the formatting options apply to the local representation of the current time.
- In PowerShell v7.1+ you can use the
-AsUTC
switch, which enable you to simplify to
Get-Date -AsUTC -UFormat %H
.
However, as shown above, instead of letting Get-Date
default to the current (invariably local) time, you can pass a [datetime]
instance as an argument to Get-Date
('s positionally implied -Date
parameter) for reformatting, and [datetime]::UtcNow
is the current time expressed in UTC.