Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell Get Date.ToString(';r';)返回错误的时间(GMT而不是本地时区)_Powershell - Fatal编程技术网

Powershell Get Date.ToString(';r';)返回错误的时间(GMT而不是本地时区)

Powershell Get Date.ToString(';r';)返回错误的时间(GMT而不是本地时区),powershell,Powershell,PowerShell没有正确显示时间,并且忽略了我的本地时区-当前是00:20(在+2 GMT),但在获取时间时显示本地时间(00:20),但错误地打印GMT 正在运行脚本的服务器上检查,并且时区和本地时间设置正确 我做错什么了吗?还是这是一个错误 $scriptStartDate = Get-Date Write-Host "time is $($scriptStartDate.ToString('r'))" # above line prints 'Sun, 14 Apr 2013 00:2

PowerShell没有正确显示时间,并且忽略了我的本地时区-当前是00:20(在+2 GMT),但在获取时间时显示本地时间(00:20),但错误地打印GMT

正在运行脚本的服务器上检查,并且时区和本地时间设置正确

我做错什么了吗?还是这是一个错误

$scriptStartDate = Get-Date
Write-Host "time is $($scriptStartDate.ToString('r'))"
# above line prints 'Sun, 14 Apr 2013 00:20:00 GMT'
# this is wrong as wrong timezone, it should be 'Sun, 14 Apr 2013 00:20:00 E.Europe'

由您确定时间是否为UTC。您可以这样做:

[DateTime]::UtcNow.ToString('r')
此格式上的说明如下:

格式化不会修改日期时间的值;所以你 格式化之前,必须将该值调整为GMT