How to display time and date:

C

Captain Dondo

I've got an embedded system. It has a web server. I want to display a
page with the system time and date - not the client time and date, but
the server time and date.

The only tools I have available to me are PHP on the http server end and
javascript on the browser end...

The webserver knows only how to serve static web pages and run cgi
scripts. (It's not apache...)

Given these limitations, is there a way to show a real-time, ticking
clock? Or should I just use PHP to show the time at the moment the page
was generated?

Thanks,

--Yan
 
N

Neredbojias

I've got an embedded system. It has a web server. I want to display a
page with the system time and date - not the client time and date, but
the server time and date.

The only tools I have available to me are PHP on the http server end and
javascript on the browser end...

The webserver knows only how to serve static web pages and run cgi
scripts. (It's not apache...)

Given these limitations, is there a way to show a real-time, ticking
clock? Or should I just use PHP to show the time at the moment the page
was generated?

There's something called rss feeds which I think can do this.
 
J

Jose

Given these limitations, is there a way to show a real-time, ticking
clock? Or should I just use PHP to show the time at the moment the page
was generated?

I don't know. However, it seems like you could set a javascript clock
based on the time of the request, and then let javascript do the
ticking. It wouldn't be -tied- to the server, but at least it would
start there and probably not go too far off.

Jose
 
A

Andy Dingley

I want to display a
page with the system time and date - not the client time and date, but
the server time and date.

In general, don't do this. There are plenty of clocks around already -
you don't need to stretch web protocols to be one too. Look at using
NTP clients to keep the time synched, if accuracy is a problem. Of
course you might be building a kiosk app, so we can't say for certain
that you shouldn't do this.


You can display client-side time and date, set accurately from the
server. Then it's up to the client side to keep ticking while the page
is displayed - of course you can refresh the page at intervals.

You can also build a client-side clock using AJAX that refreshes itself
from the server time. That's a little more client-side work, but neater.

Or you can embed an ActiveX control that reads this directly from an NTP
server (Network Time Protocol) and displays it. I used one years ago,
but can't remember if I bought it or built it. This is ugly (ActiveX)
for public access, but OK for intranets.

It might even be possible to build an NTP client out of AJAX....
 
T

Toby Inkster

Captain said:
I want to display a page with the system time and date - not the client
time and date, but the server time and date.
The only tools I have available to me are PHP on the http server end and
javascript on the browser end...

<p>The date is: <?= htmlentities( date('r') ) ?>.</p>

http://uk2.php.net/date
 
T

Toby Inkster

Captain said:
Given these limitations, is there a way to show a real-time, ticking
clock?

Ah -- only just read that.

If you can afford to be a handful of seconds inaccurate, you could use PHP
to generate some Javascript like:

<script type="text/javascript">

var servertime = new Date('<?= htmlentities(date('r')) ?>');
var clienttime = new Date();
var timeoffset = servertime - clienttime;

function alertDate ()
{
var d = new Date();
d += timeoffset;
window.alert('The server date is ' + d.toString());
}

var annoyance = window.setInterval('alertDate', 20000);

</script>

That's not been tested, so it may have one or two syntax errors, but it
should give you an idea about how to proceed.

(I felt I owed you a good answer after my previous rubbish one!)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top