PowerShell中的时间转换

时间:2018-05-24 12:22:57

标签: powershell

在下面,我得到了UTC的Timecreated时间,我想把它转换成EST。

$Windowsevnts += New-Object -TypeName PSObject -Property @{
    RDGServerName = $env:computername
    UserName = $event.Properties[0].Value
    IpAddress = [net.ipaddress]$event.Properties[1].Value
    Resource = $Event.Properties[3].Value
    TimeCreated = $event.TimeCreated
    Result = $eventtype
}

2 个答案:

答案 0 :(得分:0)

以下是代码:

$utcTime = (Get-Date $event.TimeCreated).ToUniversalTime()
$tz = [System.TimeZoneInfo]::FindSystemTimeZoneById('Eastern Standard Time')
$estTime = [System.TimeZoneInfo]::ConvertTimeFromUtc($utcTime, $tz)

答案 1 :(得分:0)

                $eventsar += New-Object -TypeName PSObject -Property @{            
                RDGServerName = $env:computername            
                UserName = $event.Properties[0].Value            
                IpAddress = [net.ipaddress]$event.Properties[1].Value            
                Resource = $Event.Properties[3].Value
                'TimeCreated in UTC' =  $event.TimeCreated         
                'TimeCreated in EST' = [System.TimeZoneInfo]::ConvertTimeBySystemTimeZoneId($event.TimeCreated, [System.TimeZoneInfo]::Local.Id, 'Eastern Standard Time')
                Result = $eventtype            
            }