What are common pitfalls when formatting dates in PHP?

Common pitfalls when formatting dates in PHP include using incorrect date format characters, not handling time zones properly, and not considering localization issues. To avoid these pitfalls, make sure to use the correct date format characters (such as 'Y' for a four-digit year), set the appropriate time zone using functions like date_default_timezone_set(), and consider using the setlocale() function for localization.

// Set the time zone to UTC
date_default_timezone_set('UTC');

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