Maxime
Maxime

Reputation: 1325

Get another timezone info, locally, using VBScript

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

Upvotes: 2

Views: 1120

Answers (1)

Maxime
Maxime

Reputation: 1325

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

Upvotes: 2

Related Questions