Powershell simplest method to get current time expressed as UTC Powershell simplest method to get current time expressed as UTC powershell powershell

Powershell simplest method to get current time expressed as UTC


Probably something like this:

[DateTime]::UtcNow.ToString('u')

Which is equivalent to:

[DateTime]::UtcNow.ToString((Get-Culture).DateTimeFormat.UniversalSortableDateTimePattern)

For the bonus, I think the most straightforward way is just to replace Z with UTC:

[DateTime]::UtcNow.ToString('u').Replace('Z','UTC')

I'm assuming you'll always want UTC since that what it seems like from your question. There doesn't appear to be a format string to get just the 3 letter time zone.


I tried this, and it also gives the result I want:

"[DateTime]::UtcNow.ToString('yyyyMMdd_HHmmss_UTC')"

It is showing time in the format 20180108_152407_UTC so you can play with the date/time formatting as you wish basically