What are the advantages of using DateTimeZone over date_default_timezone_set in PHP?

When working with time zones in PHP, it is recommended to use the DateTimeZone class over the date_default_timezone_set function for better flexibility and control. DateTimeZone allows you to easily create and manipulate time zones, while date_default_timezone_set only sets the default time zone for date and time functions. Using DateTimeZone also makes it easier to work with multiple time zones in the same script.

// Using DateTimeZone to set and work with time zones
$timezone = new DateTimeZone('America/New_York');
$date = new DateTime('now', $timezone);
echo $date->format('Y-m-d H:i:s');