Google News
logo
PHP Program to Output the current time (server time)
In the following example of PHP program to output the current time (server time) :
Program :
<?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>";
?>
Output :
The current time is 10:31:06 AM
The current time (24-hour format) is 10:31:06
The current timestamp is 1682937066
This program sets the default timezone to UTC using the `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.

The output is displayed using the `echo` statement.