Display current time with time zone in PowerShell

前端 未结 7 806
盖世英雄少女心
盖世英雄少女心 2021-02-14 02:06

I\'m trying to display the local time on my system with the TimeZone. How can I display time in this format the simplest way possible on any system?:

Time: 8:00:34 AM ES

7条回答
  •  [愿得一人]
    2021-02-14 02:51

    This is a better answer:

    $A = Get-Date                    #Returns local date/time
    $B = $A.ToUniversalTime()        #Convert it to UTC
    
    # Figure out your current offset from UTC
    $Offset = [TimeZoneInfo]::Local | Select BaseUtcOffset   
    
    #Add the Offset
    $C = $B + $Offset.BaseUtcOffset
    $C.ToString()
    

    Output: 3/20/2017 11:55:55 PM

提交回复
热议问题