ShoeLace1291 Posted July 15, 2007 Share Posted July 15, 2007 How do I loop through to display all the timezones in a dropdown menu? Link to comment https://forums.phpfreaks.com/topic/60037-loop-through-timezones/ Share on other sites More sharing options...
infid3l Posted July 15, 2007 Share Posted July 15, 2007 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. Link to comment https://forums.phpfreaks.com/topic/60037-loop-through-timezones/#findComment-298625 Share on other sites More sharing options...
ShoeLace1291 Posted July 15, 2007 Author Share Posted July 15, 2007 That's GMT right? so I've seen on some sites that use for example, GMT -800. Is that the same thing? Link to comment https://forums.phpfreaks.com/topic/60037-loop-through-timezones/#findComment-298632 Share on other sites More sharing options...
infid3l Posted July 15, 2007 Share Posted July 15, 2007 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 Link to comment https://forums.phpfreaks.com/topic/60037-loop-through-timezones/#findComment-298635 Share on other sites More sharing options...
trq Posted July 15, 2007 Share Posted July 15, 2007 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>"; ?> Link to comment https://forums.phpfreaks.com/topic/60037-loop-through-timezones/#findComment-298637 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.