In microsoft.public.scripting.vbscript message <1178560509.915804.156400
@l77g2000hsb.googlegroups.com>, Mon, 7 May 2007 10:55:09, Tom Lavedas
Post by Tom LavedasPost by SRHi Group
How will i get the time in UTC format through VB script.
Thanks in Advance
Here is an oldie, based on a posting by Walter Zackery from circa
2000 ...
wsh.echo ToUTC(now)
Function ToUTC(vDate)
with CreateObject("htmlfile")
.write("<script>var a = new Date('" & vDate & "');")
.write("a.setFullYear(" & Year(vDate) & ");")
.write("a = a.toUTCString();</script>")
.close
ToUTC = .parentWindow.a
end with
End Function
It accesses the JScript script engine inherent in WSH to use a
function available there that is not available to VBS.
For the current time/date, I see no point in passing in a VBS 'Now'
(resolution : one second), converted to a string, for Javascript to
parse. Indeed, with all combinations of preferences, can one be sure
that the VBS string will necessarily be parsed correctly? With
.write("<script>var a = new Date();")
Javascript will get the date/time. setFullYear will not be needed.
Granted, toUTCString() will not return fractional seconds but if wanted
they could be added.
Actually, if the OP wants a CDate representing the current UTC, get
Javascript to return new Date()/864e5 + N and get VBS to CDate()
that. N is the daycount from 1899-12-30 to 1970-01-01, 25569, easily
found empirically. (+new Date() is ms from 1970.0 UTC.)
It's a good idea to read the newsgroup c.l.j and its FAQ. See below.
--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6
news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.