$date = new DateTime('2022-10-31 23:59:59'); $date->setTimezone(new DateTimeZone('America/New_York')); echo $date->format('Y-m-d H:i:s'); //Output: 2022-10-31 18:59:59
$date = new DateTime('2022-10-31 23:59:59'); $date->setTimeZone(new DateTimeZone('Europe/London')); echo $date->format('Y-m-d H:i:s'); //Output: 2022-11-01 04:59:59In this example, the timezone of the $date object is changed to 'Europe/London' using the setTimeZone method. The package library for this method is the PHP DateTime class, which is built-in and does not require any additional installation.