faqts : Computers : Programming : Languages : PHP : Function Libraries : Date and Time

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

28 of 32 people (88%) answered Yes
Recently 8 of 10 people (80%) answered Yes

Entry

Is it possible to obtain the time zone the client web browser is running in?

Apr 19th, 2003 23:55
Shashank Tripathi, Richard Cook, http://snipurl.com/getTimeZoneOffset


ANSWER by SHASHANK TRIPATHI: 
April 2003 
You will need to use Javascript to achieve this. Take a look at the  
getTimezoneOffset() function. You can pass this info to your server side
script through a form submission, or an image path. Hope the following
code samples help -- 
METHOD 1 -- FORM SUBMISSION:
----------------------------
<html>
<body>
<form name="timeform">
<input type="text" name="timezone" value="">
</form>
<script language="JavaScript">
<!--
x = new Date();
currentTimeZoneOffsetInHours = x.getTimezoneOffset()/60;
document.timeform.timezone.value= currentTimeZoneOffsetInHours;
//-->
</script>
</body>
</html>
METHOD 2 -- IMAGE SUBMISSION: 
-----------------------------
<html>
<body>
<script language="JavaScript">
<!--
x = new Date();
currentTimeZoneOffsetInHours = x.getTimezoneOffset()/60;
document.write('<img src="code.php?timezone="' +
currentTimeZoneOffsetInHours + '">';
//-->
</script>
</body>
</html>
NOTES: 
1. In the second code sample, note that your program is called "code.php". 
2. Of course, neither of the above may work if user's browser has
Javascript turned off or does not support JS at all.
3. More info about the getTimeZoneOffset() function -- 
   http://snipurl.com/getTimeZoneOffset