Jump to content

Help pls: How to display updated time on webpage


Recommended Posts

Hi, how do I display the date and time on the server that updates automatically with the system clock? using the <%=now%> code displays it but you have to click refresh all the time to update the time with the system. How can I avoid clicking refresh and still my time follows the system time? Any help would be appreciated.

Link to comment
Share on other sites


If I read correctly, you are asking for a way to send the server time to the client and then update that without refreshing? I have provided a modified solution from my Chat Script.

<html><head><script>

//Written by Chozo4 (http://mechresource.myvnc.com)
//Modified from 'Chochat Chat Script'
//for selfupdating output of servertime in PHP

$t=[<?=@date("G,i,s")?>];
function timesync ()
{
$i=[24,60,60]; $t[2]++; $time='';
for ($x=2;$x>=0;$x--)
{
if ($t[$x]>=$i[$x]) {$t[$x]=0;$t[$x-1]+=1;}
$time=(($x>0)?':':'')+(($t[$x]<10)?'0':'')+$t[$x]+$time;
}
time.value=$time;
}</script></head>

<body onload=setInterval("timesync()",1000);><input name=time type=text value=' '></body>
</html>

The code above is saved to a file such as 'time.php' to see it's effect. It can be used in other languages too as long as you output the time in the form of an array which javascript can understand.

The line:

$t=[<?=@date("G,i,s")?>];

would actually output:

$t=[2,16,33];

If the output is matched regardless of the language the servertime is being output through, the script will function as expected.

edit in: Just to note: you might have to make a couple edits to support a 12-hour time format as this clock was setup mainly for a 24-hour timespan.

Edited by Chozo4
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...