/ Published in: ASP
URL: http://reusablecode.blogspot.com/2008/11/utc-and-atomic-time.html
How to obtain UTC time values and use them to make a more accurate local time value.
Expand |
Embed | Plain Text
<% ' Copyright (c) 2008, reusablecode.blogspot.com; some rights reserved. ' ' This work is licensed under the Creative Commons Attribution License. To view ' a copy of this license, visit http://creativecommons.org/licenses/by/3.0/ or ' send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California ' 94305, USA. ' Returns the current date and time (UTC) from the NIST server in Boulder, Colorado. function utcnow() dim xmlhttp dim response ' Server to query datetime from Const TimeServer = "http://time.nist.gov:13" ' Use XML HTTP object to request web page content Set xmlhttp = Server.CreateObject("Microsoft.XMLHTTP") xmlhttp.Open "GET", TimeServer, false, "", "" xmlhttp.Send response = xmlhttp.ResponseText set xmlhttp = nothing ' Parse UTC date utcnow = cDate(mid(response, 11, 2) & "/" & mid(response, 14, 2) & "/" & mid(response, 8, 2) & " " & mid(response, 16, 9)) end function ' Returns the current date and time, offset to local time zone, from the NIST server in Boulder, Colorado. ' This is more accurate than VBScript's built-in Now() function in situations where the local server is not synchronized. ' There is expected to be some lag caused by this function, but the order of magnitude should only be milliseconds. ' REQUIRES: utcnow() function atomicnow() dim utc dim offset utc = utcnow() ' The order of the dates is important here! offset = DateDiff("h", utc, now()) atomicnow = DateAdd("h", offset, utc) end function %>
You need to login to post a comment.
