Jump to content

Loop Through Timezones?


ShoeLace1291

Recommended Posts

How do I loop through to display all the timezones in a dropdown menu?

 

<?php
print "<SELECT NAME='ZONE'>";
for ($i=-8;$i<=8;$i++) {
     if($i> 0) {
        print "<OPTION VALUE='$i'>Timezone: +$i</OPTION>\n";
     } else {
        print "<OPTION VALUE='$i'>Timezone: $i</OPTION>\n";
     }
}
print "</SELECT>";
?>

 

I don't think PHP gives their names.

 

edit: Oops! fixed my mistake.

That's GMT right?  so I've seen on some sites that use for example, GMT -800.  Is that the same thing?

 

I have no idea, but I do know that all timezones are compared to GMT (Greenwich Mean Time) which is 0. The offsets are measured in +# and -#.

 

For the Western Hemisphere, you'll need these names:

 

http://terra.gg.utah.edu/timezones.html

That's GMT right?  so I've seen on some sites that use for example, GMT -800.  Is that the same thing?

 

That would be GMT -8. The valid range is from -12 to +12. So....

 

<?php

  print "<select name='timezone'>";
  foreach (range(-12,12) as $i) {
    if ($i > 0) {
        print "<option value='$i'>GMT +{$i}</option>";
     } elseif ($i == 0) {
        print "<option value='$i'>GMT</option>";
     } else {
        print "<option value='$i'>GMT {$i}</option>";
     }
  }
  print "</select>";

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.