What are common errors that can occur when working with DateTime objects in PHP?

One common error when working with DateTime objects in PHP is providing an incorrect format when parsing a date string. To avoid this error, make sure to use the correct format string that matches the date string being parsed. Another common error is not handling timezones properly, which can lead to unexpected results. Always set the correct timezone when working with DateTime objects to ensure accurate date and time calculations.

// Example of parsing a date string with the correct format
$dateString = '2022-01-01';
$date = DateTime::createFromFormat('Y-m-d', $dateString);
echo $date->format('Y-m-d');
```

```php
// Example of setting the timezone when working with DateTime objects
$date = new DateTime('now', new DateTimeZone('America/New_York'));
echo $date->format('Y-m-d H:i:s');