Are there any best practices to follow when dealing with time calculations in PHP, especially regarding time zones and daylight saving time?

When dealing with time calculations in PHP, especially when considering time zones and daylight saving time, it is best practice to always work with UTC time internally and only convert to local time for display purposes. This helps avoid issues with daylight saving time changes and ensures consistency across different time zones.

// Set default timezone to UTC
date_default_timezone_set('UTC');

// Get current UTC timestamp
$currentTimeUTC = time();

// Convert UTC timestamp to local time for display
date_default_timezone_set('America/New_York');
$currentTimeLocal = date('Y-m-d H:i:s', $currentTimeUTC);

echo "Current time in New York: " . $currentTimeLocal;