Time Zones 
Author Message
 Time Zones

Hi all,

anybody know how to get the time in GMT in VBScript?

Thanks in advance,

--- Mike ---



Fri, 30 Aug 2002 03:00:00 GMT  
 Time Zones
There isn't any native VBScript function.

Here's an example of a function that converts passed dates into UTC (aka GMT) format.  It requires
registry access to get the ActiveTimeBias registry value so it is limited to script environments
where the script client can read the registry.

=================================================

Call inputbox("",,FormatUTC(now))
Call inputbox("",,FormatUTC("2/29/00 6 AM"))
Call inputbox("",,FormatUTC("2/29/2000 6 AM"))

wscript.quit

function FormatUTC(ByVal vDate)
  '================================================
  'Converts input date/time to Universal Time
  'Coordinate (UTC) in the same format as JScripts
  'toUTCString method.
  '
  ' dayabbreviation, dd monthname yy hh:mm:ss UTC
  '
  'Example: Fri, 2 July 1999 18:17:50 UTC
  '
  '================================================
  'Verify a valid input date.  All date/times are
  'assumed to be relative to the local time zone.
  '
  'CDate handles a wide range of partial date/time
  'values, with defaults applied for missing portions.
  'The rules aren't documented but can be discovered
  'with enough experimentation.
  '
  if isdate(vdate) then
    'Explicitly converting the input with CDate ensures
    'we have a full date and time...
    '
    vdate = cdate(vdate)
  else
    err.raise &h7001,"FormatUTC","Argument is not a valid date"
  end if

  set shell = createobject("wscript.shell")

  'ActiveTimeBias is the number of minutes that UTC
  'is offset from local time.  It is added to local
  'date/time to get UTC equivalent.
  '
  strValueName = _
    "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\"_
  & "TimeZoneInformation\ActiveTimeBias"
  tmpTimeOffset = shell.regread(strValueName)

  'On Win9x platforms, ActiveTimeBias is returned
  'in a ByteArray.  On NT, it's returned as a Long.
  '
  if IsArray(tmpTimeOffset) then
    lngTimeOffset = tmpTimeOffset(1) & tmpTimeOffset(0)
  else
    lngTimeOffset = tmpTimeOffset
  end if

  dt = DateAdd("n", lngTimeOffset, vDate)

  'Extract the "fields" of the date/time and
  'reformat into UTC standard format.
  '
  dayabbr = weekdayname(weekday(dt),True) 'abbreviated

  'JScript doesn't include leading 0 on day,
  'so we don't either.
  '
  dd = datepart("d",dt)
  monnm = monthname(month(dt))
  yyyy = year(dt)

  hh = right("00" & hour(dt),2)
  mn = right("00" & minute(dt),2)
  ss = right("00" & second(dt),2)
  'hh = right("00" & datepart("h",dt),2)
  'mn = right("00" & datepart("n",dt),2)
  'ss = right("00" & datepart("s",dt),2)

  FormatUTC = _
      dayabbr & ", " _
    & dd & " " & monnm & " " & yyyy & " " _
    & hh & ":" & mn & ":" & ss _
    & " UTC"

end function

--
Michael Harris
MVP Scripting



Hi all,

anybody know how to get the time in GMT in VBScript?

Thanks in advance,

--- Mike ---



Fri, 30 Aug 2002 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Daylight saving - winter time - summer time - time zone

2. Daylight saving - winter time - summer time - time zone

3. Daylight saving - winter time - summer time - time zone

4. Time & Time Zones

5. time zones and daylight saving time

6. Formatting Time to GMT when current Time Zone not known

7. Real time From Time Zone information

8. Determining Time Zones or Server Time

9. Add Time zone to time received field in message

10. Time offset for Time Zone display?

11. UTC time and Time Zones

12. Time Zones: How do I tell which time zone I am in.

 

 
Powered by phpBB® Forum Software