What are the best practices for handling time calculations in PHP to ensure consistent and accurate results across different server configurations?

When handling time calculations in PHP, it's important to use the appropriate functions and settings to ensure consistent and accurate results across different server configurations. One common practice is to set the default timezone using the `date_default_timezone_set()` function to avoid discrepancies in time calculations. Additionally, using PHP's built-in DateTime class and methods can help with accurate date and time manipulations.

// Set the default timezone to ensure consistent time calculations
date_default_timezone_set('UTC');

// Use PHP's DateTime class for accurate date and time calculations
$datetime1 = new DateTime('2022-01-01 00:00:00');
$datetime2 = new DateTime('2022-01-02 12:00:00');

// Calculate the difference between two datetimes
$interval = $datetime1->diff($datetime2);
echo $interval->format('%R%a days %H hours %I minutes');