Re: Reading Time zone offset

Tech-Archive recommends: Fix windows errors by optimizing your registry




"Youri Ligotmi" <yl@xxxxxxxxxxxxxxx> wrote in message
news:45bf9f87$0$29486$426a34cc@xxxxxxxxxxxxxxx
Youri Ligotmi a écrit :
Richard Mueller [MVP] a écrit :
Phil wrote:

In a script I need to know the time zone offset of the computer the
script is running on, something like +0100 or -1300 etc
How can I get this information?
Thanks for your help

I use the following snippet:
========
' Obtain local Time Zone bias from machine registry.
Set objShell = CreateObject("Wscript.Shell")
lngBiasKey = objShell.RegRead("HKLM\System\CurrentControlSet\Control\"
_
& "TimeZoneInformation\ActiveTimeBias")
If (UCase(TypeName(lngBiasKey)) = "LONG") Then
lngBias = lngBiasKey
ElseIf (UCase(TypeName(lngBiasKey)) = "VARIANT()") Then
lngBias = 0
For k = 0 To UBound(lngBiasKey)
lngBias = lngBias + (lngBiasKey(k) * 256^k)
Next
End If
=======

This was designed to work on any 32-bit client, which is why I test
with
TypeName. The result (lngBias) is in minutes.

Thanks for your help. My computer is set on GMT +1 but when I run your
script I get -60 for lngBias.
Do you have some more informations on the ActiveTimeBias value?

regards

Phil
I got the answer! he time is in minutes and the offset is from *my*
location to greenwich, so from greenwich to *my* location I have to take
the opposite.
Thanks again Richard

Yes. I'm on GMT+6 (Central Time US) and my bias is 360. You subtract the
bias value (lngBias in minutes) from the UTC date/time value to convert to
local time. Note that during daylight savings, this value changes. For me,
lngBias is 300 during daylight savings. This makes the conversion from UTC
to local time correct. If you don't what the daylight savings adjustment,
then use Bias rather than ActiveTimeBias in the registry.

--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab web site - http://www.rlmueller.net
--


.



Relevant Pages

  • Re: Reading Time zone offset
    ... script is running on, something like +0100 or -1300 etc ... I use the following snippet: ... ' Obtain local Time Zone bias from machine registry. ... lngBias = lngBiasKey ...
    (microsoft.public.scripting.vbscript)
  • Re: How convert GMT to LocalTime in Access 2003
    ... Dim udtTZI As TimeZoneInfo ... 'The bias is the difference, in minutes, ... 'between UTC time and local time. ...
    (microsoft.public.access.queries)
  • Re: password as changed
    ... The pwdLastSet attribute of the user object represents the date/time when ... program to display the value in local time (correcting for the local time ... lngBias = lngBiasKey ... Dim lngAdjust, lngDate, lngHigh, lngLow ...
    (microsoft.public.windows.server.active_directory)
  • Re: password as changed
    ... value in local time would be ... lngBias = lngBiasKey ... ' Retrieve pwdLastSet attribute. ... Dim lngAdjust, lngDate, lngHigh, lngLow ...
    (microsoft.public.windows.server.active_directory)
  • Re: Locale timeZoneInformation
    ... which tells whether the system is currently in daylight savings time mode or not. ... minutes related to GMT 0 (Greenwich), but it answers it with the inverse sign. ... i.e. my local bias is -180 and if I evaluate #bias, ... typically displayed (which is the offset of the local time from GMT). ...
    (comp.lang.smalltalk.dolphin)