SPS Home    >   Dgreath    >   JavaScript Code Library    >   Display Current Time

JAVASCRIPT CODE TO DISPLAY CURRENT TIME

The following script will display formatted current time on the face of a webpage within a span container providing a means to render it in the middle of a paragraph. The code consists of a timer that times for one second, then calls a routine that extracts the current time using the Date() function. A one shot signal is needed to trigger the first iteration and must be positioned after the first reference in the body.  This trigger could be either in a footer script or via the body onload attribute as shown below.. Time displayed is user's local time.

DEMONSTRATION

The current time is  local time.

JS Code for Head Container


  

Event Trigger


  

Body Container XHTML