7. WRITE A PHP PROGRAM TO DISPLAY A DIGITAL CLOCK WHICH DISPLAYS THE CURRENT TIME OF THE SERVER.
SOLUTION 1 & SOLUTION 2
1. If xampp is in the system, save the program in C:\xampp\htdocs [start apache in
xampp control panel]
2. If no xampp in the system, save the program in C:\Program Files\Apache Group\Apache2\htdocs & Open Google Chrome & type //localhost/prog7.php
prog7.php
p {
color:yellow;
font-size:90px;
position:absolute;
top: 40%;
left: 50%;
transform: translate[-50%, -50%];
}
body {
background-color:maroon;
}
STEPS :[ click on image to zoom ]
OUTPUT :[ click on image to zoom ]
To Display Current Running Clock in PHP, we use a PHP script where we set the default time zone and time, a jQuery code to take that response from the PHP script then show it to the web page.
You can say it partially display running time or live clock use PHP. Here we create 2 files, one is where we code HTML and JS then a PHP script to show time.
- index.html
- timeScript.php
In This Article
- 1 PHP Program to Display Current Running Clock
- 2 index.html
- 3 timeScript.php
- 3.1 Related
index.html
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | $[document].ready[function[] { setInterval[runningTime,1000]; }]; functionrunningTime[]{ $.ajax[{ url: 'timeScript.php', success:function[data]{ $['#runningTime'].html[data]; }, }]; }
|
timeScript.php
|
Output:
Code Highlights:
- Create an HTML
div
element where we show the time. - Include a jQuery script which and use
setInterval[]
to call PHP script at a given time. - At last, we create a PHP file where we set time zone and time using PHP
date
function.
Here is a complete PHP program to display a digital clock that displays the current time of the server or set default time zone.
If you wan to know more about set interval function //www.w3schools.com/jsref/met_win_setinterval.asp
Also Check:
- How JavaScript For Loop Works [Complete Guide With Example]
- Create Repository & Push Code To GitHub First Time
- Migrate WordPress Site To New Host Manually
- Set-up Firebase Project using Firebase Console
Happy Coding..!
Was this article helpful?
YesNo
Bikash
My name is Bikash Kr. Panda. I own and operate PHPCODER.TECH. I am a web Programmer by profession and working on more than 50 projects to date. Currently I am working on the web-based project and all the CMS and frameworks which are based on PHP.