What are best practices for setting and handling timezones in PHP to avoid issues like incorrect time outputs?

When working with timezones in PHP, it is important to set the correct timezone to avoid issues such as incorrect time outputs. One best practice is to set the timezone explicitly at the beginning of your script using the `date_default_timezone_set()` function. Additionally, when working with date and time functions, always use timezone-aware functions like `DateTime` and `DateTimeZone` to ensure accurate results.

// Set the timezone to your desired timezone
date_default_timezone_set('America/New_York');

// Create a new DateTime object with the current time
$now = new DateTime();

// Format the current time in the desired timezone
echo $now->format('Y-m-d H:i:s');