What are the best practices for formatting dates in PHP using the date function?

When formatting dates in PHP using the date function, it is important to follow best practices to ensure consistency and readability. One common practice is to use the date function with a specific format string that represents the desired date format. This format string can include various placeholders for different date components such as day, month, year, and time. It is also recommended to use the date_default_timezone_set function to set the desired timezone for the date output.

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

// Format the current date in a specific format
$formatted_date = date('Y-m-d H:i:s');

echo $formatted_date;