GMT Time Format 
Author Message
 GMT Time Format

Is there a quick way in VBScript to format a string of the current date
and time in GMT format (Mon, 31 Dec 1999 23:59:59 EST)?  The
FormatDateTime function doesn't seem to have what I need.

Sent via Deja.com
http://www.*-*-*.com/



Sun, 20 Jul 2003 22:13:04 GMT  
 GMT Time Format
(This NOT for browser use since it reads the registry for ActiveTimeBias)...

msgbox FormatUTC(now)

function FormatUTC(ByVal vDate)
  '================================================
  'Converts input date/time to Universal Time
  'Coordinate (UTC) in the same format as JScript's
  'Date().toUTCString() method.
  '
  ' dayabbreviation, dd monthname yy hh:mm:ss UTC
  '
  'Example: Fri, 2 Jul 1999 18:17:50 UTC
  '
  '================================================
  if isdate(vdate) then
    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)

  'ActiveTimeBias can be REG_BINARY or REG_DWORD
  'depending on the OS version...
  '
  if IsArray(tmpTimeOffset) then
    'it's REG_BINARY w/ 2 bytes significant
    lngTimeOffset = tmpTimeOffset(0) + (tmpTimeOffset(1)*(2^8))
  else
    'it's REG_DWORD
    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),true)
  yyyy = year(dt)

  hh = right("00" & hour(dt),2)
  mn = right("00" & minute(dt),2)
  ss = right("00" & second(dt),2)

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

end function

--
Michael Harris
Microsoft.MVP.Scripting
--

Please do not email questions - post them to the newsgroup instead.
--

Quote:

> Is there a quick way in VBScript to format a string of the current date
> and time in GMT format (Mon, 31 Dec 1999 23:59:59 EST)?  The
> FormatDateTime function doesn't seem to have what I need.

> Sent via Deja.com
> http://www.deja.com/



Mon, 21 Jul 2003 09:33:14 GMT  
 
 [ 2 post ] 

 Relevant Pages 

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

2. GMT time, BootUp time

3. converting PST/PDT time to GMT time

4. How to Convert GMT(Greenwich) Time to short date and time and vice versa

5. Function to return CST time given GMT time?

6. what is visitors GMT time

7. How to get the GMT Time using VBScript?

8. Calculate GMT Time with VBScript

9. how to calculate the GMT (greenwich mean time)

10. Converting Times to GMT

11. GMT Time

12. GMT to ET and ET to GMT

 

 
Powered by phpBB® Forum Software