How to display time and date:

Discussion in 'HTML' started by Captain Dondo, Apr 19, 2006.

  1. 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
    Captain Dondo, Apr 19, 2006
    #1
    1. Advertising

  2. Captain Dondo

    Neredbojias Guest

    To further the education of mankind, Captain Dondo <>
    vouchsafed:

    > 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.

    --
    Neredbojias
    Infinity can have limits.
    Neredbojias, Apr 19, 2006
    #2
    1. Advertising

  3. Captain Dondo

    Jose Guest

    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
    --
    The price of freedom is... well... freedom.
    for Email, make the obvious change in the address.
    Jose, Apr 19, 2006
    #3
  4. Captain Dondo

    Andy Dingley Guest

    On Wed, 19 Apr 2006 10:10:35 -0700, Captain Dondo <>
    wrote:

    >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....
    Andy Dingley, Apr 20, 2006
    #4
  5. Captain Dondo

    Toby Inkster Guest

    Captain Dondo wrote:

    > 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

    --
    Toby A Inkster BSc (Hons) ARCS
    Contact Me ~ http://tobyinkster.co.uk/contact
    Toby Inkster, Apr 20, 2006
    #5
  6. Captain Dondo

    Toby Inkster Guest

    Captain Dondo wrote:

    > 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!)

    --
    Toby A Inkster BSc (Hons) ARCS
    Contact Me ~ http://tobyinkster.co.uk/contact
    Toby Inkster, Apr 20, 2006
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matt
    Replies:
    1
    Views:
    594
    Matthew Speed
    Nov 8, 2003
  2. Chris Berg
    Replies:
    0
    Views:
    784
    Chris Berg
    Oct 27, 2003
  3. Peter Grison

    Date, date date date....

    Peter Grison, May 28, 2004, in forum: Java
    Replies:
    10
    Views:
    3,243
    Michael Borgwardt
    May 30, 2004
  4. Keith Cochrane
    Replies:
    2
    Views:
    608
    Keith Cochrane
    Aug 6, 2006
  5. Summu82
    Replies:
    5
    Views:
    860
    Richard Heathfield
    Jun 7, 2006
Loading...

Share This Page