Computing server time zone difference in classic ASP ... take 2

Antic from Jodohost pointed me to an even more elegant solution: use mixed JavaScript/VBScript to get the result. JavaScript can compute the timezone difference with a built-in function and VBScript can then use the results.

Here is the minimum code to get the desired result:
<script runat="server" language="jscript">
var TZDiff = new Date().getTimezoneOffset();

</script>
<% Response.Write TZDiff %>

Of course, if you care about ASP performance, you might not want to invoke two script interpreter engines in a single page. In that case, a more optimized solution is:

GetTZ.asp:
<%@ LANGUAGE=JScript %>
<% Application("TZOffset") = new Date().getTimezoneOffset() %>

Any other ASP page:
<%
If Not IsNumeric(Application("TZOffset")) Then Server.Execute("GetTZ.asp")
' use Application("TZOffset") from here on
%>

1 comment:

Ivan Pepelnjak said...

Another method depending on the IIS ability to read the registry is documented here.

Post a Comment

Post a Comment