Creating a DateTime object with a specific UTC DateTime in PowerShell

前端 未结 6 1158
野趣味
野趣味 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:44

    You can use the SpecifyKind method:

    PS C:\IT\s3> $timestamp

    Wednesday, July 18, 2018 7:57:14 PM

    PS C:\IT\s3> $timestamp.kind

    Unspecified

    PS C:\IT\s3> $utctimestamp = [DateTime]::SpecifyKind($timestamp,[DateTimeKind]::Utc)

    PS C:\IT\s3> $utctimestamp

    Wednesday, July 18, 2018 7:57:14 PM

    PS C:\IT\s3> $utctimestamp.kind

    Utc

提交回复
热议问题