PHP: Create a List of Time Zones

Sometimes, you want to create a list of available time zones to prompt your user to select his/her time zone. Fortunately, PHP offers timezone_identifiers_list (PHP 5 >= 5.2.0). You can create your list easily, using a function.


 * Timezones list with GMT offset
 * @return array
 * @link
function tz_list() {
  $zones_array = array();
  $timestamp = time();
  foreach(timezone_identifiers_list() as $key => $zone) {
    $zones_array[$key]['zone'] = $zone;
    $zones_array[$key]['diff_from_GMT'] = 'UTC/GMT ' . date('P', $timestamp);
  return $zones_array;

The above function returns an array with all timezones and the GMT offset for each timezone.


<div style="margin-top: 20px;">
  <select style="font-family: 'Courier New', Courier, monospace; width: 450px;">
    <option value="0">Please, select timezone</option>
    <?php foreach(tz_list() as $t) { ?>
      <option value="<?php print $t['zone'] ?>">
        <?php print $t['diff_from_GMT'] . ' - ' . $t['zone'] ?>
    <?php } ?>


Artikel terkait:   jQuery: Simple Weekdays Name & Timepicker with jQuery Timepicker

Isi Komentar

Alamat email Anda tidak akan dipublikasikan. Ruas yang wajib ditandai *

twenty three − thirteen =

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top