Windows ISO 8601 timestamp

后端 未结 3 1326
长发绾君心
长发绾君心 2021-02-13 00:31

I need to convert a date in Windows PowerShell to the ISO 8601 format.

In Linux/Unix it was no problem with

TZ=0 date -d \"\"          


        
相关标签:
3条回答
  • 2021-02-13 01:08

    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
    
    0 讨论(0)
  • 2021-02-13 01:12

    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"

    0 讨论(0)
  • 2021-02-13 01:21

    Get-Date supports Unix formatting strings with the -UFormat parameter. You can reuse it:

    Get-Date -UFormat '+%Y-%m-%dT%H:%M:%S.000Z'
    
    0 讨论(0)
提交回复
热议问题