What are some best practices for handling time calculations in PHP to account for variations like daylight savings time?

When working with time calculations in PHP, it is important to account for variations like daylight savings time to ensure accurate results. One way to handle this is by using the DateTime class, which automatically adjusts for daylight savings time changes. By utilizing this class and specifying the correct time zone, you can ensure that your time calculations are accurate regardless of any time changes.

// Set the default time zone to the desired location
date_default_timezone_set('America/New_York');

// Create a DateTime object with the specified date and time
$date = new DateTime('2022-03-13 12:00:00');

// Perform time calculations as needed
$date->modify('+1 day');

// Output the result
echo $date->format('Y-m-d H:i:s');