在本地获取另一个时区信息,使用VBScript [英] Get another timezone info, locally, using VBScript
问题描述
我有一个中央服务器,在CET / CEST(西欧)时区。
>我想知道这个服务器与其他计算机在BRT / BRST(巴西)时区和KST(韩国)时区的时差。 p>
防火墙设置阻止我直接查询电脑或时间服务器。
我认为所有的信息是在本地可用,因为当我使用Windows的附加时钟功能时,我可以在任何时区获得时间,在这里和那里记录DST。
挑战是如何在VBScript中执行此操作。
我已经看到我可以在
code> \\HKEY_LOCAL_MACHINE\\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones
,但似乎没有考虑到DST。
d这样做,愿意分享他/她的发现?
感谢您的帮助
Maxime
正如JosefZ所建议的那样,使用PowerShell是一个很好的主意;
Dim PSCommand
Set Shell = CreateObject(Wscript.shell)
PSCommand =powershell -command [String] $ zone ='Korea Standard Time'; [TimeZoneInfo] $ tz = [TimeZoneInfo] :: FindSystemTimeZoneById($ zone); [TimeZoneInfo] $ local_tz = [TimeZoneInfo] :: Local; [DateTimeOffset] $ now = [DateTimeOffset] :: UtcNow; [TimeSpan] $ zone_offset = $ tz.GetUtcOffset($ now); [TimeSpan] $ local_offset = $ local_tz.GetUtcOffset($ now); $ diff = $ zone_offset - $ local_offset; $ mydiff = $ diff.Hours; Write-Host $ mydiff
Set Executor = Shell.Exec(PSCommand)
executor.StdIn.Close
wscript.echo executor.StdOut.ReadAll()
I have a little challenge I'd like your help with.
I have a central server, in CET/CEST (Western Europe) timezone.
I'd like to know, at any time, the time difference between this server and other computers, in BRT/BRST (Brazil) timezone and KST (Korea) timezone.
The firewall settings prevent me from querying the computers directly, or a time server.
I think all the information is available locally, since when I use Windows 'Additional Clocks' feature, I can get the time in any timezone, accounting for DST both here and there.
The challenge is how to do it in VBScript.
I have seen that I can read registry keys at
\\HKEY_LOCAL_MACHINE\\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones
but it does not seem to account for DST.
As anyone ever tried to do something like this, and is willing to share his/her findings?
Thank you for your help
Maxime
As JosefZ suggested, using PowerShell was a very good idea;
Dim PSCommand
Set Shell = CreateObject("Wscript.shell")
PSCommand = "powershell -command [String]$zone = 'Korea Standard Time';[TimeZoneInfo]$tz = [TimeZoneInfo]::FindSystemTimeZoneById($zone);[TimeZoneInfo]$local_tz = [TimeZoneInfo]::Local;[DateTimeOffset]$now = [DateTimeOffset]::UtcNow;[TimeSpan]$zone_offset = $tz.GetUtcOffset($now);[TimeSpan]$local_offset = $local_tz.GetUtcOffset($now);$diff = $zone_offset - $local_offset;$mydiff = $diff.Hours;Write-Host $mydiff"
Set Executor = Shell.Exec(PSCommand)
executor.StdIn.Close
wscript.echo executor.StdOut.ReadAll()
这篇关于在本地获取另一个时区信息,使用VBScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!