What are the advantages of using the DateTime class in PHP for handling date and time calculations?

When working with date and time calculations in PHP, using the DateTime class provides a more object-oriented and flexible approach compared to traditional functions like date() and strtotime(). The DateTime class allows for easier manipulation of dates, time zones, and intervals, making it simpler to perform operations such as adding or subtracting days, months, or years.

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

// Add 1 day to the current date
$now->modify('+1 day');

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