What are some best practices for handling date and time formatting in PHP to ensure cross-platform compatibility?

When working with date and time formatting in PHP, it is important to use the `DateTime` class and its methods to ensure cross-platform compatibility. This class provides a consistent way to manipulate dates and times regardless of the underlying system settings. By using the `format()` method with standard format codes, you can generate date and time strings that are easily understood across different platforms.

// Create a new DateTime object with the current date and time
$date = new DateTime();

// Format the date and time using standard format codes
$formatted_date = $date->format('Y-m-d H:i:s');

// Output the formatted date and time
echo $formatted_date;