How can the DateTime() function be used to handle date and time in PHP?

The DateTime() function in PHP can be used to handle date and time by creating a new DateTime object that represents a specific date and time. This object can then be manipulated using various methods provided by the DateTime class, such as formatting the date and time, adding or subtracting intervals, comparing dates, and more.

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

// Output the current date and time in a specific format
echo $date->format('Y-m-d H:i:s');

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

// Output the new date and time
echo $date->format('Y-m-d H:i:s');