How does PHP handle time zone changes and daylight saving time when calculating date differences?

When calculating date differences in PHP, it's important to consider time zone changes and daylight saving time to ensure accurate results. PHP provides functions like `date_default_timezone_set()` and `date()` with the 'O' format specifier to handle time zone conversions and DST adjustments.

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

// Get the current date and time in the specified time zone
$currentDateTime = new DateTime('now');

// Calculate the date difference
$startDate = new DateTime('2022-01-01');
$endDate = new DateTime('2022-12-31');
$dateDiff = $endDate->diff($startDate);

// Output the date difference
echo $dateDiff->format('%R%a days');