I am reading a field that appears to be in GMT and I need to convert it to
what ever the local system timezone is in. Does anyone have a VBScript
function that can perform this, taking into account daylight savings.
Thanks
I am reading a field that appears to be in GMT and I need to convert it to
what ever the local system timezone is in. Does anyone have a VBScript
function that can perform this, taking into account daylight savings.
Thanks
Bob Smith wrote:
I read the time zone bias from the local registry. For example:
>I am reading a field that appears to be in GMT and I need to convert it to
> what ever the local system timezone is in. Does anyone have a VBScript
> function that can perform this, taking into account daylight savings.
=======
' 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
lngTZBias = lngBiasKey
ElseIf (UCase(TypeName(lngBiasKey)) = "VARIANT()") Then
lngTZBias = 0
For k = 0 To UBound(lngBiasKey)
lngTZBias = lngTZBias + (lngBiasKey(k) * 256^k)
Next
End If
=======
The ActiveTimeBias key takes daylight savings into account. The value of
lngTZBias is in minutes. An example VBScript program that uses this code to
convert an Integer8 attribute (pwdLastSet in this case) from UTC (what used
to be called GMT) into the local time zone is linked here:
http://www.rlmueller.net/Programs/Integer8Date.txt
--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--
Bob Smith schrieb:In addition/as alternative to Richard Mueller's pure VBScript solution,
> I am reading a field that appears to be in GMT and I need to convert it to
> what ever the local system timezone is in. Does anyone have a VBScript
> function that can perform this, taking into account daylight savings.
>
> Thanks
>
it may be possible to let another language do the hard work: This
VBScript program:
Option Explicit
Dim oFS : Set oFS = CreateObject( "Scripting.FileSystemObject" )
Dim sJSF : sJSF = oFS.GetAbsolutePathName( ".\jsgmt.wsc" )
Dim oJS : Set oJS = GetObject( "script:" & sJSF )
Dim aTests : aTests = Array( _
#1/1/1970 00:00:00#, Now, #4/13/2008 01:02:03#, #4/13/1953 01:02:03# _
)
Const cnWi = 20
WScript.Echo Left( "GTM" & Space( cnWi ), cnWi ), "LOC"
Dim dtGMT, dtLoc
For Each dtGMT In aTests
dtLoc = oJS.getJSLOC( Year( dtGMT ), Month( dtGMT ), Day(
dtGMT ) _
, Hour( dtGMT ), Minute( dtGMT ), Second(
dtGMT ) )
WScript.Echo Left( dtGMT & Space( cnWi ), cnWi ), dtLoc
Next
loads the jsgmt.wsc component using the "script:" protocol (so
registration is not necessary):
<?xml version="1.0"?>
<component>
<registration
description="jsgmt"
progid="jsgmt.WSC"
version="1.00"
classid="{d0ccb637-bd0c-4c90-a4bd-7473f499d35a}">
</registration>
<public>
<method name="getJSGMT"></method>
<method name="getJSLOC"></method>
</public>
<script language="JavaScript">
<![CDATA[
function getJSGMT( iY, iMo, iD, iH, iMi, sS )
{ return new Date( iY, iMo - 1, iD, iH, iMi, sS ).toUTCString();
}
function getJSLOC( iY, iMo, iD, iH, iMi, sS )
{ return new Date( Date.UTC( iY, iMo - 1, iD, iH, iMi, sS ) ).getVarDate();
}
]]>
</script>
</component>
Output:
cscript twsc1.vbs
GTM LOC
01.01.1970 01.01.1970 01:00:00
11.12.2008 23:25:20 12.12.2008 00:25:20
13.04.2008 01:02:03 13.04.2008 03:02:03
13.04.1953 01:02:03 13.04.1953 03:02:03
You just saved me a lot of time. I have the script doing what I need now.
Thanks for that, your a saviour!
"Richard Mueller [MVP]" wrote:
> Bob Smith wrote:
>>
> >I am reading a field that appears to be in GMT and I need to convert it to
> > what ever the local system timezone is in. Does anyone have a VBScript
> > function that can perform this, taking into account daylight savings.
> I read the time zone bias from the local registry. For example:
> =======
> ' 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
> lngTZBias = lngBiasKey
> ElseIf (UCase(TypeName(lngBiasKey)) = "VARIANT()") Then
> lngTZBias = 0
> For k = 0 To UBound(lngBiasKey)
> lngTZBias = lngTZBias + (lngBiasKey(k) * 256^k)
> Next
> End If
> =======
> The ActiveTimeBias key takes daylight savings into account. The value of
> lngTZBias is in minutes. An example VBScript program that uses this code to
> convert an Integer8 attribute (pwdLastSet in this case) from UTC (what used
> to be called GMT) into the local time zone is linked here:
>
> http://www.rlmueller.net/Programs/Integer8Date.txt
>
> --
> Richard Mueller
> MVP Directory Services
> Hilltop Lab - http://www.rlmueller.net
> --
>
>
>
In microsoft.public.scripting.vbscript message <494195ac$0$31331$9b4e6d9
3@xxxxxx-online.net>, Thu, 11 Dec 2008 23:35:13,
ekkehard.horner <ekkehard.horner@xxxxxx> posted:
I think that you can write that date as #1953/04/13 01:02:03# and have
> #4/13/1953 01:02:03#
it understood by VBS everywhere; that will be easier on the European
eye, being close to ISO 8601.
And if you set your system to show ISO dates, the first of those will
>11.12.2008 23:25:20
>13.04.2008 01:02:03
not be misunderstood by any passing Americans.
Aside : My site has algorithms for converting date/time, GMT to/from
elsewhere, using TZ strings; they could perhaps be converted to VBS.
--
(c) John Stockton, nr London, UK. ?@merlyn.demon.co.uk Turnpike v6.05.
Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
| Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Time Zone - Restore Missing Time Zones | Brink | Tutorials | 0 | 29 Nov 2008 |
| Time Zone | Brink | Tutorials | 8 | 28 Nov 2008 |
| Changing the time zone changes the appointment time in calendar | Richard Kirby | .NET General | 0 | 23 Apr 2008 |
| travelling laptop - set time & time zone | A G Smith | Vista General | 11 | 31 Mar 2008 |
| There is No Time Zone !!! | mrwill | Vista General | 7 | 28 Mar 2008 |