我目前正在尝试找出让用户选择时区的最佳方法。当你注册分析时,我喜欢谷歌这样做。
<<p> 谷歌方式/strong>1)从下拉菜单中选择国家(这个很容易,人们习惯于在默认的国家列表中找到自己的国家)
2)显示第二个下拉列表,其中包含所选国家的所有可用时区。这使得选择时区变得非常快速和容易。特别是因为用户甚至不需要关心这个国家是否只有一个时区。
PHP方式
每个推荐(在堆栈溢出搜索之后)都使用DateTimeZone库。这个输出对用户不友好,因为很难找到您的时区。你甚至不能使用键盘,因为每个时区都有欧洲/非洲/等前缀。
回到我的问题。有没有一个图书馆,上面有所有国家的时区地图?如果没有,是否有更简单的方法让用户选择时区?有http://php.net/manual/en/datetimezone.listidentifiers.php;从列表的每个元素中去掉"continent/"应该很容易。页面上的一个例子甚至在代码中有这个
我找到了一个unicode文档,它结合了夏令时工作方式相同的国家的时区。这个列表将选择的数量减少到100个。我用这个列表创建了一个包含所有条目的MySQL表。
您可以由此轻松创建一个下拉列表。使用PHP函数date_default_timezone_set()
和php_code
将正确设置时区。
下面是MySQL表结构。
INSERT INTO `timezone` (`timezone_id`, `php_code`, `timezone_description`) VALUES
(1, 'Etc/GMT+12', '(UTC-12:00) International Date Line West'),
(2, 'Etc/GMT+11', '(UTC-11:00) Coordinated Universal Time-11'),
(3, 'Etc/GMT+10', '(UTC-10:00) Hawaii'),
(4, 'America/Anchorage', '(UTC-09:00) Alaska'),
(5, 'America/Santa_Isabel', '(UTC-08:00) Baja California'),
(6, 'PST8PDT', '(UTC-08:00) Pacific Time (US & Canada)'),
(7, 'Etc/GMT+7', '(UTC-07:00) Arizona'),
(8, 'America/Chihuahua', '(UTC-07:00) Chihuahua, La Paz, Mazatlan'),
(9, 'MST7MDT', '(UTC-07:00) Mountain Time (US & Canada)'),
(10, 'Etc/GMT+6', '(UTC-06:00) Central America'),
(11, 'CST6CDT', '(UTC-06:00) Central Time (US & Canada)'),
(12, 'America/Mexico_City', '(UTC-06:00) Guadalajara, Mexico City, Monterrey'),
(13, 'America/Regina', '(UTC-06:00) Saskatchewan'),
(14, 'Etc/GMT+5', '(UTC-05:00) Bogota, Lima, Quito'),
(15, 'EST5EDT', '(UTC-05:00) Eastern Time (US & Canada)'),
(16, 'America/Indianapolis', '(UTC-05:00) Indiana (East)'),
(17, 'America/Caracas', '(UTC-04:30) Caracas'),
(18, 'America/Asuncion', '(UTC-04:00) Asuncion'),
(19, 'America/Halifax', '(UTC-04:00) Atlantic Time (Canada)'),
(20, 'America/Cuiaba', '(UTC-04:00) Cuiaba'),
(21, 'Etc/GMT+4', '(UTC-04:00) Georgetown, La Paz, Manaus, San Juan'),
(22, 'America/Santiago', '(UTC-04:00) Santiago'),
(23, 'America/St_Johns', '(UTC-03:30) Newfoundland'),
(24, 'America/Sao_Paulo', '(UTC-03:00) Brasilia'),
(25, 'America/Buenos_Aires', '(UTC-03:00) Buenos Aires'),
(26, 'Etc/GMT+3', '(UTC-03:00) Cayenne, Fortaleza'),
(27, 'America/Godthab', '(UTC-03:00) Greenland'),
(28, 'America/Montevideo', '(UTC-03:00) Montevideo'),
(29, 'America/Bahia', '(UTC-03:00) Salvador'),
(30, 'Etc/GMT+2', '(UTC-02:00) Coordinated Universal Time-02'),
(31, 'Etc/GMT+2', '(UTC-02:00) Mid-Atlantic'),
(32, 'Atlantic/Azore', '(UTC-01:00) Azores'),
(33, 'Etc/GMT+1', '(UTC-01:00) Cape Verde Is.'),
(34, 'Africa/Casablanca', '(UTC) Casablanca'),
(35, 'Etc/GMT', '(UTC) Coordinated Universal Time'),
(36, 'Europe/London', '(UTC) Dublin, Edinburgh, Lisbon, London'),
(37, 'Atlantic/Reykjavik', '(UTC) Monrovia, Reykjavik'),
(38, 'Europe/Berlin', '(UTC+01:00) Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna'),
(39, 'Europe/Budapest', '(UTC+01:00) Belgrade, Bratislava, Budapest, Ljubljana, Prague'),
(40, 'Europe/Paris', '(UTC+01:00) Brussels, Copenhagen, Madrid, Paris'),
(41, 'Europe/Warsaw', '(UTC+01:00) Sarajevo, Skopje, Warsaw, Zagreb'),
(42, 'Etc/GMT-1', '(UTC+01:00) West Central Africa'),
(43, 'Africa/Windhoek', '(UTC+01:00) Windhoek'),
(44, 'Europe/Bucharest', '(UTC+02:00) Athens, Bucharest'),
(45, 'Asia/Beirut', '(UTC+02:00) Beirut'),
(46, 'Africa/Cairo', '(UTC+02:00) Cairo'),
(47, 'Asia/Damascus', '(UTC+02:00) Damascus'),
(48, 'Asia/Nicosia', '(UTC+02:00) E. Europe'),
(49, 'Africa/Johannesburg', '(UTC+02:00) Harare, Pretoria'),
(50, 'Europe/Kiev', '(UTC+02:00) Helsinki, Kyiv, Riga, Sofia, Tallinn, Vilnius'),
(51, 'Europe/Istanbul', '(UTC+02:00) Istanbul'),
(52, 'Asia/Jerusalem', '(UTC+02:00) Jerusalem'),
(53, 'Asia/Amman', '(UTC+03:00) Amman'),
(54, 'Asia/Baghdad', '(UTC+03:00) Baghdad'),
(55, 'Europe/Kaliningrad', '(UTC+03:00) Kaliningrad, Minsk'),
(56, 'Asia/Riyadh', '(UTC+03:00) Kuwait, Riyadh'),
(57, 'Africa/Nairobi', '(UTC+03:00) Nairobi'),
(58, 'Asia/Tehran', '(UTC+03:30) Tehran'),
(59, 'Asia/Dubai', '(UTC+04:00) Abu Dhabi, Muscat'),
(60, 'Asia/Baku', '(UTC+04:00) Baku'),
(61, 'Europe/Moscow', '(UTC+04:00) Moscow, St. Petersburg, Volgograd'),
(62, 'Indian/Mauritius', '(UTC+04:00) Port Louis'),
(63, 'Asia/Tbilisi', '(UTC+04:00) Tbilisi'),
(64, 'Asia/Yerevan', '(UTC+04:00) Yerevan'),
(65, 'Asia/Kabul', '(UTC+04:30) Kabul'),
(66, 'Asia/Karachi', '(UTC+05:00) Islamabad, Karachi'),
(67, 'Etc/GMT-5', '(UTC+05:00) Tashkent'),
(68, 'Asia/Calcutta', '(UTC+05:30) Chennai, Kolkata, Mumbai, New Delhi'),
(69, 'Asia/Colombo', '(UTC+05:30) Sri Jayawardenepura'),
(70, 'Asia/Katmandu', '(UTC+05:45) Kathmandu'),
(71, 'Etc/GMT-6', '(UTC+06:00) Astana'),
(72, 'Asia/Dhaka', '(UTC+06:00) Dhaka'),
(73, 'Asia/Yekaterinburg', '(UTC+06:00) Ekaterinburg'),
(74, 'Asia/Rangoon', '(UTC+06:30) Yangon (Rangoon)'),
(75, 'Asia/Bangkok', '(UTC+07:00) Bangkok, Hanoi, Jakarta'),
(76, 'Asia/Novosibirsk', '(UTC+07:00) Novosibirsk'),
(77, 'Asia/Shanghai', '(UTC+08:00) Beijing, Chongqing, Hong Kong, Urumqi'),
(78, 'Asia/Krasnoyarsk', '(UTC+08:00) Krasnoyarsk'),
(79, 'Etc/GMT-8', '(UTC+08:00) Kuala Lumpur, Singapore'),
(80, 'Australia/Perth', '(UTC+08:00) Perth'),
(81, 'Asia/Taipei', '(UTC+08:00) Taipei'),
(82, 'Asia/Ulaanbaatar', '(UTC+08:00) Ulaanbaatar'),
(83, 'Asia/Irkutsk', '(UTC+09:00) Irkutsk'),
(84, 'Etc/GMT-9', '(UTC+09:00) Osaka, Sapporo, Tokyo'),
(85, 'Asia/Seoul', '(UTC+09:00) Seoul'),
(86, 'Australia/Adelaide', '(UTC+09:30) Adelaide'),
(87, 'Australia/Darwin', '(UTC+09:30) Darwin'),
(88, 'Australia/Brisbane', '(UTC+10:00) Brisbane'),
(89, 'Australia/Sydney', '(UTC+10:00) Canberra, Melbourne, Sydney'),
(90, 'Etc/GMT-10', '(UTC+10:00) Guam, Port Moresby'),
(91, 'Australia/Hobart', '(UTC+10:00) Hobart'),
(92, 'Asia/Yakutsk', '(UTC+10:00) Yakutsk'),
(93, 'Etc/GMT-11', '(UTC+11:00) Solomon Is., New Caledonia'),
(94, 'Asia/Vladivostok', '(UTC+11:00) Vladivostok'),
(95, 'Pacific/Auckland', '(UTC+12:00) Auckland, Wellington'),
(96, 'Etc/GMT-12', '(UTC+12:00) Coordinated Universal Time+12'),
(97, 'Pacific/Fiji', '(UTC+12:00) Fiji'),
(98, 'Asia/Magadan', '(UTC+12:00) Magadan'),
(99, 'Etc/GMT-13', '(UTC+13:00) Nuku''alofa'),
(100, 'Pacific/Apia', '(UTC+13:00) Samoa');