[nycphp-talk] timezone dropdown help

David Krings ramons at
Fri Jan 26 18:16:06 EST 2007

Aniesh joseph wrote:
> hi
> I need to make a drop down in my web site in a registration form. From the
> drop down user can select the his desired time zone. My question is, I want
> to capture user's timezone using javascript and it will be shown as slected
> when at the time of registration. I got a javascript, it will capture 
> only timezoneoffset.  Is anyrelation between timezone offset and name? 
> Is ie available as table? Can anyne help me to d this or by suggest 
> another method ?
> regards
> joseph

Some time ago I asked a similar question and someone on this list was so 
nice to provide me with the ECMAScript for the client side to pull out 
the time zone bias.

The general code is this one

       if(!isset($_COOKIE['GMT_bias'])) {
	     <script type="text/javascript">
	     var Cookies = {};
	     * @name = string, name of cookie
	     * @value = string, value of cookie
	     * @days = int, number of days before cookie expires
	     Cookies.create = function (name, value, days) {
	          if (days) {
		    var date = new Date();
		    date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
		    var expires = "; expires=" + date.toGMTString();
	     } else {
		    var expires = "";
	     document.cookie = name + "=" + value + expires + "; path=/";
	     this[name] = value;
	     var now = new Date();
	     window.location = "<?php echo $_SERVER['PHP_SELF'];?>";
       } else {
	     echo $_COOKIE['GMT_bias'];

It will simply echo the bias in minutes, which should be good enough to 
find out the client's time zone by name assuming you have some table for 
lookups or can pull that from the server system (no idea how that works, 
but other programming languages can do that. Since PHP can do anything 
including cooking breakfast, there should be some way).

At least it gets you started.


More information about the talk mailing list