How can the date() function be used to format dates in PHP?
The date() function in PHP can be used to format dates by specifying a format string that defines how the date should be displayed. This function takes a timestamp as its first parameter (which can be obtained using time() or strtotime()) and an optional format string as its second parameter. The format string can include various placeholders for different date and time components, such as day, month, year, hour, minute, and second.
$date = time(); // Get the current timestamp
$formatted_date = date("Y-m-d H:i:s", $date); // Format the date as "YYYY-MM-DD HH:MM:SS"
echo $formatted_date; // Output the formatted date