title: Convert selected time and timezone to a set timezone
body: <p>I'm trying to make a small script that takes 2 user inputs (a timezone and a date + time) and converts it to a predefined timezone. I have really no idea on how to handle this. See my script below for an idea of what I want to achieve.</p>
  
  <pre><code>&lt;?
  //I'm so glad I finally made this
  $timezones = array(
  'Pacific/Midway'    =&gt; "(GMT-11:00) Midway Island",
  'US/Samoa'          =&gt; "(GMT-11:00) Samoa",
  'US/Hawaii'         =&gt; "(GMT-10:00) Hawaii",
  'US/Alaska'         =&gt; "(GMT-09:00) Alaska",
  'US/Pacific'        =&gt; "(GMT-08:00) Pacific Time (US &amp;amp; Canada)",
  'America/Tijuana'   =&gt; "(GMT-08:00) Tijuana",
  'US/Arizona'        =&gt; "(GMT-07:00) Arizona",
  'US/Mountain'       =&gt; "(GMT-07:00) Mountain Time (US &amp;amp; Canada)",
  'America/Chihuahua' =&gt; "(GMT-07:00) Chihuahua",
  'America/Mazatlan'  =&gt; "(GMT-07:00) Mazatlan",
  'America/Mexico_City' =&gt; "(GMT-06:00) Mexico City",
  'America/Monterrey' =&gt; "(GMT-06:00) Monterrey",
  'Canada/Saskatchewan' =&gt; "(GMT-06:00) Saskatchewan",
  'US/Central'        =&gt; "(GMT-06:00) Central Time (US &amp;amp; Canada)",
  'US/Eastern'        =&gt; "(GMT-05:00) Eastern Time (US &amp;amp; Canada)",
  'US/East-Indiana'   =&gt; "(GMT-05:00) Indiana (East)",
  'America/Bogota'    =&gt; "(GMT-05:00) Bogota",
  'America/Lima'      =&gt; "(GMT-05:00) Lima",
  'America/Caracas'   =&gt; "(GMT-04:30) Caracas",
  'Canada/Atlantic'   =&gt; "(GMT-04:00) Atlantic Time (Canada)",
  'America/La_Paz'    =&gt; "(GMT-04:00) La Paz",
  'America/Santiago'  =&gt; "(GMT-04:00) Santiago",
  'Canada/Newfoundland'  =&gt; "(GMT-03:30) Newfoundland",
  'America/Buenos_Aires' =&gt; "(GMT-03:00) Buenos Aires",
  'Greenland'         =&gt; "(GMT-03:00) Greenland",
  'Atlantic/Stanley'  =&gt; "(GMT-02:00) Stanley",
  'Atlantic/Azores'   =&gt; "(GMT-01:00) Azores",
  'Atlantic/Cape_Verde' =&gt; "(GMT-01:00) Cape Verde Is.",
  'Africa/Casablanca' =&gt; "(GMT) Casablanca",
  'Europe/Dublin'     =&gt; "(GMT) Dublin",
  'Europe/Lisbon'     =&gt; "(GMT) Lisbon",
  'Europe/London'     =&gt; "(GMT) London",
  'Africa/Monrovia'   =&gt; "(GMT) Monrovia",
  'Europe/Amsterdam'  =&gt; "(GMT+01:00) Amsterdam",
  'Europe/Belgrade'   =&gt; "(GMT+01:00) Belgrade",
  'Europe/Berlin'     =&gt; "(GMT+01:00) Berlin",
  'Europe/Bratislava' =&gt; "(GMT+01:00) Bratislava",
  'Europe/Brussels'   =&gt; "(GMT+01:00) Brussels",
  'Europe/Budapest'   =&gt; "(GMT+01:00) Budapest",
  'Europe/Copenhagen' =&gt; "(GMT+01:00) Copenhagen",
  'Europe/Ljubljana'  =&gt; "(GMT+01:00) Ljubljana",
  'Europe/Madrid'     =&gt; "(GMT+01:00) Madrid",
  'Europe/Paris'      =&gt; "(GMT+01:00) Paris",
  'Europe/Prague'     =&gt; "(GMT+01:00) Prague",
  'Europe/Rome'       =&gt; "(GMT+01:00) Rome",
  'Europe/Sarajevo'   =&gt; "(GMT+01:00) Sarajevo",
  'Europe/Skopje'     =&gt; "(GMT+01:00) Skopje",
  'Europe/Stockholm'  =&gt; "(GMT+01:00) Stockholm",
  'Europe/Vienna'     =&gt; "(GMT+01:00) Vienna",
  'Europe/Warsaw'     =&gt; "(GMT+01:00) Warsaw",
  'Europe/Zagreb'     =&gt; "(GMT+01:00) Zagreb",
  'Europe/Athens'     =&gt; "(GMT+02:00) Athens",
  'Europe/Bucharest'  =&gt; "(GMT+02:00) Bucharest",
  'Africa/Cairo'      =&gt; "(GMT+02:00) Cairo",
  'Africa/Harare'     =&gt; "(GMT+02:00) Harare",
  'Europe/Helsinki'   =&gt; "(GMT+02:00) Helsinki",
  'Europe/Istanbul'   =&gt; "(GMT+02:00) Istanbul",
  'Asia/Jerusalem'    =&gt; "(GMT+02:00) Jerusalem",
  'Europe/Kiev'       =&gt; "(GMT+02:00) Kyiv",
  'Europe/Minsk'      =&gt; "(GMT+02:00) Minsk",
  'Europe/Riga'       =&gt; "(GMT+02:00) Riga",
  'Europe/Sofia'      =&gt; "(GMT+02:00) Sofia",
  'Europe/Tallinn'    =&gt; "(GMT+02:00) Tallinn",
  'Europe/Vilnius'    =&gt; "(GMT+02:00) Vilnius",
  'Asia/Baghdad'      =&gt; "(GMT+03:00) Baghdad",
  'Asia/Kuwait'       =&gt; "(GMT+03:00) Kuwait",
  'Europe/Moscow'     =&gt; "(GMT+03:00) Moscow",
  'Africa/Nairobi'    =&gt; "(GMT+03:00) Nairobi",
  'Asia/Riyadh'       =&gt; "(GMT+03:00) Riyadh",
  'Europe/Volgograd'  =&gt; "(GMT+03:00) Volgograd",
  'Asia/Tehran'       =&gt; "(GMT+03:30) Tehran",
  'Asia/Baku'         =&gt; "(GMT+04:00) Baku",
  'Asia/Muscat'       =&gt; "(GMT+04:00) Muscat",
  'Asia/Tbilisi'      =&gt; "(GMT+04:00) Tbilisi",
  'Asia/Yerevan'      =&gt; "(GMT+04:00) Yerevan",
  'Asia/Kabul'        =&gt; "(GMT+04:30) Kabul",
  'Asia/Yekaterinburg' =&gt; "(GMT+05:00) Ekaterinburg",
  'Asia/Karachi'      =&gt; "(GMT+05:00) Karachi",
  'Asia/Tashkent'     =&gt; "(GMT+05:00) Tashkent",
  'Asia/Kolkata'      =&gt; "(GMT+05:30) Kolkata",
  'Asia/Kathmandu'    =&gt; "(GMT+05:45) Kathmandu",
  'Asia/Almaty'       =&gt; "(GMT+06:00) Almaty",
  'Asia/Dhaka'        =&gt; "(GMT+06:00) Dhaka",
  'Asia/Novosibirsk'  =&gt; "(GMT+06:00) Novosibirsk",
  'Asia/Bangkok'      =&gt; "(GMT+07:00) Bangkok",
  'Asia/Jakarta'      =&gt; "(GMT+07:00) Jakarta",
  'Asia/Krasnoyarsk'  =&gt; "(GMT+07:00) Krasnoyarsk",
  'Asia/Chongqing'    =&gt; "(GMT+08:00) Chongqing",
  'Asia/Hong_Kong'    =&gt; "(GMT+08:00) Hong Kong",
  'Asia/Irkutsk'      =&gt; "(GMT+08:00) Irkutsk",
  'Asia/Kuala_Lumpur' =&gt; "(GMT+08:00) Kuala Lumpur",
  'Australia/Perth'   =&gt; "(GMT+08:00) Perth",
  'Asia/Singapore'    =&gt; "(GMT+08:00) Singapore",
  'Asia/Taipei'       =&gt; "(GMT+08:00) Taipei",
  'Asia/Ulaanbaatar'  =&gt; "(GMT+08:00) Ulaan Bataar",
  'Asia/Urumqi'       =&gt; "(GMT+08:00) Urumqi",
  'Asia/Seoul'        =&gt; "(GMT+09:00) Seoul",
  'Asia/Tokyo'        =&gt; "(GMT+09:00) Tokyo",
  'Asia/Yakutsk'      =&gt; "(GMT+09:00) Yakutsk",
  'Australia/Adelaide' =&gt; "(GMT+09:30) Adelaide",
  'Australia/Darwin'  =&gt; "(GMT+09:30) Darwin",
  'Australia/Brisbane' =&gt; "(GMT+10:00) Brisbane",
  'Australia/Canberra' =&gt; "(GMT+10:00) Canberra",
  'Pacific/Guam'      =&gt; "(GMT+10:00) Guam",
  'Australia/Hobart'  =&gt; "(GMT+10:00) Hobart",
  'Australia/Melbourne' =&gt; "(GMT+10:00) Melbourne",
  'Pacific/Port_Moresby' =&gt; "(GMT+10:00) Port Moresby",
  'Australia/Sydney'  =&gt; "(GMT+10:00) Sydney",
  'Asia/Vladivostok'  =&gt; "(GMT+10:00) Vladivostok",
  'Asia/Magadan'      =&gt; "(GMT+11:00) Magadan",
  'Pacific/Auckland'  =&gt; "(GMT+12:00) Auckland",
  'Pacific/Fiji'      =&gt; "(GMT+12:00) Fiji",
  'Asia/Kamchatka'    =&gt; "(GMT+12:00) Kamchatka",
  );
  //So happy I finished making that
  if(!$_POST){
  ?&gt;
  &lt;form method="post"&gt;
  &lt;input type="text" id="datepicker" name="date" /&gt;
  &lt;select name="zone"&gt;
  &lt;?
  
  foreach($timezones as $key =&gt; $value){
  echo "&lt;option name=\"zone\" value=\"$key\"&gt;$value&lt;/option&gt;";
  }
  ?&gt;
  &lt;/select&gt;
  &lt;input type="submit" value="Convert" /&gt;
  &lt;/form&gt;
  &lt;?
  }
  if($_POST){
  $date = $_POST['date']; //comes in format "m/d/Y h:i"
  $zone = $_POST['zone']; //is in php format e.g. "Pacific/Auckland"
  
  echo "You selected ".$date." in the timezone ".$zone."&lt;br&gt;";
  echo "The time in New Zealand is ".$result." which is GMT+12";
  }
  ?&gt;
  </code></pre>
  
  <p>EDIT: NEW CODE</p>
  
  <pre><code>&lt;?
  //I'm so glad I finally made this
  $timezones = array(
  'Pacific/Midway'    =&gt; "(GMT-11:00) Midway Island",
  'US/Samoa'          =&gt; "(GMT-11:00) Samoa",
  'US/Hawaii'         =&gt; "(GMT-10:00) Hawaii",
  'US/Alaska'         =&gt; "(GMT-09:00) Alaska",
  'US/Pacific'        =&gt; "(GMT-08:00) Pacific Time (US &amp;amp; Canada)",
  'America/Tijuana'   =&gt; "(GMT-08:00) Tijuana",
  'US/Arizona'        =&gt; "(GMT-07:00) Arizona",
  'US/Mountain'       =&gt; "(GMT-07:00) Mountain Time (US &amp;amp; Canada)",
  'America/Chihuahua' =&gt; "(GMT-07:00) Chihuahua",
  'America/Mazatlan'  =&gt; "(GMT-07:00) Mazatlan",
  'America/Mexico_City' =&gt; "(GMT-06:00) Mexico City",
  'America/Monterrey' =&gt; "(GMT-06:00) Monterrey",
  'Canada/Saskatchewan' =&gt; "(GMT-06:00) Saskatchewan",
  'US/Central'        =&gt; "(GMT-06:00) Central Time (US &amp;amp; Canada)",
  'US/Eastern'        =&gt; "(GMT-05:00) Eastern Time (US &amp;amp; Canada)",
  'US/East-Indiana'   =&gt; "(GMT-05:00) Indiana (East)",
  'America/Bogota'    =&gt; "(GMT-05:00) Bogota",
  'America/Lima'      =&gt; "(GMT-05:00) Lima",
  'America/Caracas'   =&gt; "(GMT-04:30) Caracas",
  'Canada/Atlantic'   =&gt; "(GMT-04:00) Atlantic Time (Canada)",
  'America/La_Paz'    =&gt; "(GMT-04:00) La Paz",
  'America/Santiago'  =&gt; "(GMT-04:00) Santiago",
  'Canada/Newfoundland'  =&gt; "(GMT-03:30) Newfoundland",
  'America/Buenos_Aires' =&gt; "(GMT-03:00) Buenos Aires",
  'Greenland'         =&gt; "(GMT-03:00) Greenland",
  'Atlantic/Stanley'  =&gt; "(GMT-02:00) Stanley",
  'Atlantic/Azores'   =&gt; "(GMT-01:00) Azores",
  'Atlantic/Cape_Verde' =&gt; "(GMT-01:00) Cape Verde Is.",
  'Africa/Casablanca' =&gt; "(GMT) Casablanca",
  'Europe/Dublin'     =&gt; "(GMT) Dublin",
  'Europe/Lisbon'     =&gt; "(GMT) Lisbon",
  'Europe/London'     =&gt; "(GMT) London",
  'Africa/Monrovia'   =&gt; "(GMT) Monrovia",
  'Europe/Amsterdam'  =&gt; "(GMT+01:00) Amsterdam",
  'Europe/Belgrade'   =&gt; "(GMT+01:00) Belgrade",
  'Europe/Berlin'     =&gt; "(GMT+01:00) Berlin",
  'Europe/Bratislava' =&gt; "(GMT+01:00) Bratislava",
  'Europe/Brussels'   =&gt; "(GMT+01:00) Brussels",
  'Europe/Budapest'   =&gt; "(GMT+01:00) Budapest",
  'Europe/Copenhagen' =&gt; "(GMT+01:00) Copenhagen",
  'Europe/Ljubljana'  =&gt; "(GMT+01:00) Ljubljana",
  'Europe/Madrid'     =&gt; "(GMT+01:00) Madrid",
  'Europe/Paris'      =&gt; "(GMT+01:00) Paris",
  'Europe/Prague'     =&gt; "(GMT+01:00) Prague",
  'Europe/Rome'       =&gt; "(GMT+01:00) Rome",
  'Europe/Sarajevo'   =&gt; "(GMT+01:00) Sarajevo",
  'Europe/Skopje'     =&gt; "(GMT+01:00) Skopje",
  'Europe/Stockholm'  =&gt; "(GMT+01:00) Stockholm",
  'Europe/Vienna'     =&gt; "(GMT+01:00) Vienna",
  'Europe/Warsaw'     =&gt; "(GMT+01:00) Warsaw",
  'Europe/Zagreb'     =&gt; "(GMT+01:00) Zagreb",
  'Europe/Athens'     =&gt; "(GMT+02:00) Athens",
  'Europe/Bucharest'  =&gt; "(GMT+02:00) Bucharest",
  'Africa/Cairo'      =&gt; "(GMT+02:00) Cairo",
  'Africa/Harare'     =&gt; "(GMT+02:00) Harare",
  'Europe/Helsinki'   =&gt; "(GMT+02:00) Helsinki",
  'Europe/Istanbul'   =&gt; "(GMT+02:00) Istanbul",
  'Asia/Jerusalem'    =&gt; "(GMT+02:00) Jerusalem",
  'Europe/Kiev'       =&gt; "(GMT+02:00) Kyiv",
  'Europe/Minsk'      =&gt; "(GMT+02:00) Minsk",
  'Europe/Riga'       =&gt; "(GMT+02:00) Riga",
  'Europe/Sofia'      =&gt; "(GMT+02:00) Sofia",
  'Europe/Tallinn'    =&gt; "(GMT+02:00) Tallinn",
  'Europe/Vilnius'    =&gt; "(GMT+02:00) Vilnius",
  'Asia/Baghdad'      =&gt; "(GMT+03:00) Baghdad",
  'Asia/Kuwait'       =&gt; "(GMT+03:00) Kuwait",
  'Europe/Moscow'     =&gt; "(GMT+03:00) Moscow",
  'Africa/Nairobi'    =&gt; "(GMT+03:00) Nairobi",
  'Asia/Riyadh'       =&gt; "(GMT+03:00) Riyadh",
  'Europe/Volgograd'  =&gt; "(GMT+03:00) Volgograd",
  'Asia/Tehran'       =&gt; "(GMT+03:30) Tehran",
  'Asia/Baku'         =&gt; "(GMT+04:00) Baku",
  'Asia/Muscat'       =&gt; "(GMT+04:00) Muscat",
  'Asia/Tbilisi'      =&gt; "(GMT+04:00) Tbilisi",
  'Asia/Yerevan'      =&gt; "(GMT+04:00) Yerevan",
  'Asia/Kabul'        =&gt; "(GMT+04:30) Kabul",
  'Asia/Yekaterinburg' =&gt; "(GMT+05:00) Ekaterinburg",
  'Asia/Karachi'      =&gt; "(GMT+05:00) Karachi",
  'Asia/Tashkent'     =&gt; "(GMT+05:00) Tashkent",
  'Asia/Kolkata'      =&gt; "(GMT+05:30) Kolkata",
  'Asia/Kathmandu'    =&gt; "(GMT+05:45) Kathmandu",
  'Asia/Almaty'       =&gt; "(GMT+06:00) Almaty",
  'Asia/Dhaka'        =&gt; "(GMT+06:00) Dhaka",
  'Asia/Novosibirsk'  =&gt; "(GMT+06:00) Novosibirsk",
  'Asia/Bangkok'      =&gt; "(GMT+07:00) Bangkok",
  'Asia/Jakarta'      =&gt; "(GMT+07:00) Jakarta",
  'Asia/Krasnoyarsk'  =&gt; "(GMT+07:00) Krasnoyarsk",
  'Asia/Chongqing'    =&gt; "(GMT+08:00) Chongqing",
  'Asia/Hong_Kong'    =&gt; "(GMT+08:00) Hong Kong",
  'Asia/Irkutsk'      =&gt; "(GMT+08:00) Irkutsk",
  'Asia/Kuala_Lumpur' =&gt; "(GMT+08:00) Kuala Lumpur",
  'Australia/Perth'   =&gt; "(GMT+08:00) Perth",
  'Asia/Singapore'    =&gt; "(GMT+08:00) Singapore",
  'Asia/Taipei'       =&gt; "(GMT+08:00) Taipei",
  'Asia/Ulaanbaatar'  =&gt; "(GMT+08:00) Ulaan Bataar",
  'Asia/Urumqi'       =&gt; "(GMT+08:00) Urumqi",
  'Asia/Seoul'        =&gt; "(GMT+09:00) Seoul",
  'Asia/Tokyo'        =&gt; "(GMT+09:00) Tokyo",
  'Asia/Yakutsk'      =&gt; "(GMT+09:00) Yakutsk",
  'Australia/Adelaide' =&gt; "(GMT+09:30) Adelaide",
  'Australia/Darwin'  =&gt; "(GMT+09:30) Darwin",
  'Australia/Brisbane' =&gt; "(GMT+10:00) Brisbane",
  'Australia/Canberra' =&gt; "(GMT+10:00) Canberra",
  'Pacific/Guam'      =&gt; "(GMT+10:00) Guam",
  'Australia/Hobart'  =&gt; "(GMT+10:00) Hobart",
  'Australia/Melbourne' =&gt; "(GMT+10:00) Melbourne",
  'Pacific/Port_Moresby' =&gt; "(GMT+10:00) Port Moresby",
  'Australia/Sydney'  =&gt; "(GMT+10:00) Sydney",
  'Asia/Vladivostok'  =&gt; "(GMT+10:00) Vladivostok",
  'Asia/Magadan'      =&gt; "(GMT+11:00) Magadan",
  'Pacific/Auckland'  =&gt; "(GMT+12:00) Auckland",
  'Pacific/Fiji'      =&gt; "(GMT+12:00) Fiji",
  'Asia/Kamchatka'    =&gt; "(GMT+12:00) Kamchatka",
  );
  //So happy I finished making that
  if(!$_POST){
  ?&gt;
  &lt;form method="post"&gt;
  &lt;input type="text" id="datepicker" name="date" /&gt;
  &lt;select name="zone"&gt;
  &lt;?
  
  foreach($timezones as $key =&gt; $value){
  echo "&lt;option name=\"zone\" value=\"$key\"&gt;$value&lt;/option&gt;";
  }
  ?&gt;
  &lt;/select&gt;
  &lt;input type="submit" value="Convert" /&gt;
  &lt;/form&gt;
  &lt;?
  }
  if($_POST){
  $date = $_POST['date']; //comes in format "m/d/Y h:i"
  $zone = $_POST['zone']; //is in php format e.g. "Pacific/Auckland"
  
  
  
  try {
  $date = new DateTime($_POST['date'], new DateTimeZone($_POST['zone']));
  $date-&gt;setTimezone(new DateTimeZone('Pacific/Auckland'));
  $result = $date-&gt;format('m/d/Y H:i');
  } catch (Exception $e) {
  echo $e-&gt;getMessage();
  }
  echo $result;
  
  
  
  
  }
  ?&gt;
  </code></pre>