How can the date() function in PHP be used to handle time zone conversions efficiently?

When using the date() function in PHP to handle time zone conversions efficiently, it is important to set the default time zone using the date_default_timezone_set() function to the desired time zone before calling the date() function. This ensures that the output of the date() function is in the correct time zone without the need for manual conversions.

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

// Get the current date and time in the specified time zone
$currentDateTime = date('Y-m-d H:i:s');
echo $currentDateTime;