5 PHP Clock Examples

This post contains a total of 5 Hand-picked PHP Clock Examples. All the PHP Clocks are made using PHP, and some of the source codes uses js and css for styling and for the clock.

You can use the source codes of these PHP Clocks for your own personal use or educational use ( With credits to Original Owner ), if you want to modify the code and use it for something else then you can ask for the permission from the owner.

Related Posts

Click a Code to Copy it, and Hover over a video to play it.

#1 – By byww

A basic single line PHP Clock by byww that displays the current time. ( Source )

<?php
	echo strftime('%H : %M : %S');
?>

#2 – By Hitanshu Soni

Made by Hitanshu Soni, it mostly uses js for the clock. ( Source )

<!-- Created by Hitanshu Soni -->

<?php

date_default_timezone_set('UTC');

?>

<script>

var d = new Date(<?php echo time() * 1000 ?>);

function digitalClock() {

d.setTime(d.getTime() + 1000);

var hrs = d.getHours();

var mins = d.getMinutes();

var secs = d.getSeconds();

mins = (mins < 10 ? "0" : "") + mins;

secs = (secs < 10 ? "0" : "") + secs;

var apm = (hrs < 12) ? "am" : "pm";

hrs = (hrs > 12) ? hrs - 12 : hrs;

hrs = (hrs == 0) ? 12 : hrs;

var ctime = hrs + ":" + mins + ":" + secs + " " + apm;

document.getElementById("clock").firstChild.nodeValue = ctime;

}

window.onload = function() {

digitalClock();

setInterval('digitalClock()', 1000);

}

</script>

<div id="clock"> </div>

#3 – By Aldityan Yoga Pratama

Basic PHP Clock by Aldityan Yoga Pratama. ( Source )

<?php
    $jam="3";
    $menit=$jam*60;
    $detik=$jam*3600;
    print "<hr>";
    print "<center>";
    echo "3 jam=$menit menit";
    print "</hr";
    echo "60 menit=$detik detik";
?>

#4 – By Ravina kumaras

Digital PHP Clock by Ravina kumaras. Its styled using css to look more like a digital clock. ( Source )

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="refresh" content="1"/>
<style>
p {
color:white;
font-size:90px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
body{background-color:black;}
</style>
<p> <?php echo date(" h: i : s A");?> </p>
</head>

#5 – By freshL

A World clock made by freshL. The clock displays the current time of different time zones from around the world. ( Source )

<?php
//set the timezone
date_default_timezone_set("Australia/Melbourne");
echo "Time in Sydney, AU: " . date("h:i:s A d/m/Y");
echo "<br /><br />";
//set the timezone
date_default_timezone_set("America/New_York");
echo "Time in New York, NY: " . date("h:i:s A d/m/Y");
echo "<br /><br />";

//set the timezone
date_default_timezone_set("America/Denver");
echo "Time in Denver, CO: " . date("h:i:s A d/m/Y");
echo "<br /><br />";

//set the timezone
date_default_timezone_set("America/Los_Angeles");
echo "Time in LosAngeles: " . date("h:i:s A d/m/Y");
echo "<br /><br />";

//set the timezone
date_default_timezone_set("Europe/Amsterdam");
echo "<b>Time in Amsterdam</b>: " . date("h:i:s A d/m/Y");
echo "<br /><br />";

//set the timezone
date_default_timezone_set("Pacific/Fiji");
echo "Time in Fiji: " . date("h:i:s A d/m/Y");

echo "<br /><br />";
// Complete list of supported timezones: http://php.net/manual/en/timezones.php
?>