How can PHP handle daylight saving time changes when working with timestamps?

When working with timestamps in PHP, it is important to consider daylight saving time changes to ensure accurate time calculations. One way to handle this is by using the DateTime class in PHP, which automatically adjusts for daylight saving time changes based on the timezone provided. By using this class, PHP will handle the conversion between timestamps and dates correctly, taking into account any changes in daylight saving time.

// Set the timezone to the desired timezone
date_default_timezone_set('America/New_York');

// Create a new DateTime object with the timestamp
$timestamp = 1612362000; // Example timestamp
$date = new DateTime("@$timestamp");

// Format the date as needed
echo $date->format('Y-m-d H:i:s');