Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Web
Expertise: Intermediate
Nov 24, 1999

Discover the Time Difference in JavaScript and ASP

If you need to calculate a time difference between your Web server and visitors to your site, look into the JavaScript getTimezoneOffset() method. It returns the time zone difference in minutes between the local time on the client machine and Greenwich Mean Time (GMT).

This script (utime.asp) uses Active Server Pages (ASP) and JavaScript to put the browser's current time into a hidden form field. When the user clicks OK, your server can read the offset value.

 
<%@ Language=VBScript %>
<HTML>
<HEAD>
<script language=javascript>
function dotime() {
curtime = new Date();
a = curtime.getTimezoneOffset()
document.forms[0].thetime.value=a;
}
</script>
</HEAD>
<BODY>
<%
if Request("thetime") <> "" then
   Response.Write "<H2>The time offset in minutes is: " & request("thetime") & "</H2>"
else
%>
<H2>Click OK to tell us the time offset.</H2>
<form name=utime action="utime.asp">
<input name=thetime type="hidden" >
<input type=submit onclick="dotime();" value=" OK ">
</form>
<%end if%>
</BODY>
</HTML> 

Once you have the user's offset, you can calculate the time zone difference from your server.

Ken Cox
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date