Get another timezone info, locally, using VBScript

时光毁灭记忆、已成空白 提交于 2019-12-11 01:54:25

问题


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


回答1:


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()


来源:https://stackoverflow.com/questions/39405867/get-another-timezone-info-locally-using-vbscript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!