How can the PHP function date() be used to format a timestamp in a specific way?

To format a timestamp in a specific way using the PHP function date(), you can provide a format string as the second parameter to the function. This format string can include various placeholders for different parts of the date and time, such as day, month, year, hour, minute, and second. By customizing the format string, you can output the timestamp in the desired format.

$timestamp = time(); // Get the current timestamp
$formatted_date = date('Y-m-d H:i:s', $timestamp); // Format the timestamp as 'YYYY-MM-DD HH:MM:SS'
echo $formatted_date; // Output the formatted date