You are here

7 May 2013

Convert time and date from one time zone to another in PHP.

Source code viewer
  1. $date = new DateTime('2013-06-07 15:37:00', new DateTimeZone('Europe/Tallinn'));
  2.  
  3. date_default_timezone_set('Europe/London');
  4.  
  5. echo date('Y-m-d H:i', $date->format('U'));
  6.  
  7. // --------------------------------------------------------------------------------------------------------------------
  8.  
  9. // date_default_timezone_set is not thread safe. If you change your time zone to often you will have problems, use this:
  10.  
  11. $date = new DateTime('2013-06-07 15:37:00', new DateTimeZone('Europe/Tallinn'));
  12.  
  13. $date->setTimezone(new DateTimeZone('Pacific/Chatham'));
  14.  
  15. echo $date->format('Y-m-d H:i');
Programming Language: PHP