<?php
// Set the default timezone
date_default_timezone_set('UTC');
// Output the current time
echo "The current time is " . date("h:i:s A") . "<br>";
// Output the current time in 24-hour format
echo "The current time (24-hour format) is " . date("H:i:s") . "<br>";
// Output the current timestamp
echo "The current timestamp is " . time() . "<br>";
?>
The current time is 10:31:06 AM
The current time (24-hour format) is 10:31:06
The current timestamp is 1682937066
date_default_timezone_set()
` function. It then uses the `date()
` function to format the current time in various ways, including a 12-hour format with AM/PM indicator, a 24-hour format, and the current timestamp using the `time()
` function. echo
` statement.