How can the DateTime class in PHP be utilized to format dates for output in a specific format?
To format dates for output in a specific format using the DateTime class in PHP, you can create a new DateTime object with the date you want to format, and then use the format() method to specify the desired format. This method allows you to customize the output by using different format characters such as 'Y' for year, 'm' for month, 'd' for day, 'H' for hour, 'i' for minute, and 's' for second.
$date = new DateTime('2022-01-15');
$formatted_date = $date->format('Y-m-d H:i:s');
echo $formatted_date;