Creating a DateTime object with a specific UTC DateTime in PowerShell

前端 未结 6 1224
野趣味
野趣味 2021-02-02 07:23

I\'m trying to create a DateTime object with a specific UTC timestamp in PowerShell. What\'s the simplest way to do this?

I tried:

Get-Date
         


        
6条回答
  •  [愿得一人]
    2021-02-02 07:39

    The DateTime object itself is being created with the proper UTC time. But when PowerShell prints it out it converts it to my local culture and time zone, thus the difference.

    Proof:

    $UtcTime = Get-Date -Date "1970-01-01 00:00:00Z"
    $UtcTime.ToUniversalTime()
    

提交回复
热议问题