What potential pitfalls should be considered when calculating time differences in PHP?

When calculating time differences in PHP, potential pitfalls to consider include differences in timezones, daylight saving time adjustments, and leap years. To ensure accurate calculations, it is recommended to use PHP's DateTime class along with the setTimeZone() method to handle timezones properly.

// Example code to calculate time difference while considering timezones
$date1 = new DateTime('2022-01-01 12:00:00', new DateTimeZone('America/New_York'));
$date2 = new DateTime('2022-01-01 15:00:00', new DateTimeZone('Europe/London'));

$date1->setTimeZone(new DateTimeZone('UTC'));
$date2->setTimeZone(new DateTimeZone('UTC'));

$interval = $date1->diff($date2);

echo $interval->format('%H:%I:%S');