11 November 2022

Working with timezones can be tricky and if you do migration of data from/to somewhere. You might have to correct timezones. This snippet shows how you can change dates based on timezone difference.

Source code viewer
  1. $given = new DateTime("2018-08-30T10:00:00", new DateTimeZone("Europe/Tallinn"));
  2. $given->setTimezone(new DateTimeZone("UTC"));
  3. $output = $given->format("Y-m-d\\TH:i:s");
  4.  
  5. echo $given->format("Y-m-d\\TH:i:s"); // Output: 2018-08-30T07:00:00
  6.  
Programming Language: PHP