Windows ISO 8601 timestamp
Get-Date
supports Unix formatting strings with the -UFormat
parameter. You can reuse it:
Get-Date (Get-Date).ToUniversalTime() -UFormat '+%Y-%m-%dT%H:%M:%S.000Z'
PowerShell's Get-Date
supports standard .NET time formats. The o
round-trip format complies with ISO 8601. Like so,
Get-Date -Format "o"
2017-08-15T12:10:34.4443084+03:00
Old question but since none of the other answers has it, if you're looking for UTC, this seems to do it:
(Get-Date).ToUniversalTime().ToString("o")
The following works both in Windows PowerShell 5.1 and PowerShell 7.0 on Windows/OS X:
(Get-Date).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.fffK")
2020-12-01T22:31:41.402Z
If you don't want your milliseconds, then format string would be "yyyy-MM-ddTHH:mm:ss.000K"