title: How to convert time from one timezone to another in PHP
body: <p>I have a code see below. The time zone for the time <code>16:17</code> is <code>Europe/Vilnius</code>. My goal is to apply time zone <code>$tz2 = 'Africa/Dakar'</code> and get <code>16:17</code> time in <code>Africa/Dakar</code> time zone.   </p>
  
  <pre><code>$tz1 = 'Europe/Vilnius';
  $tz2 = 'Africa/Dakar';
  $a='16';
  $b='17';
  $match_time = date("H:i", strtotime($a.":".$b));
  $dt1 = new DateTime($match_time, $tz1);
  $dt2 = new DateTime($match_time, $tz2);
  
  echo "match date".$match_time;
  echo "dt1".$dt1;
  echo "dt2".$dt2;
  </code></pre>
  
  <p>I tried many ways to do that. Right now this code gives me an error: </p>
  
  <blockquote>
    <p>FATAL ERROR Uncaught Error: Call to a member function format() on string in /home4/phptest/public_html/code.php70(5) : eval()'d code:8 Stack trace: #0 /home4/phptest/public_html/code.php70(5): eval() #1 {main} thrown on line number 8</p>
  </blockquote>
  
  <p>My question how to fix a code to get the result, and is this a convenient way to do such conversion? </p>