Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Current Time & date 1

Status
Not open for further replies.

kwunder

Technical User
Jun 2, 2001
860
GB
I'm looking for code that will display the current time & date on my website. I've seen one on another site which shows an image of a book withe the time and date stamped on it. Thats the kind of thing I'm after

Any ideas?

Cheers
 
Hi kwunder,

I've used this code, which can be enhanced with a few lines more. You need a <span> tag to insert the date/time string on your page. Here's the code:
Code:
<script type=&quot;text/javascript&quot;>
function setToday() {
  var months = new Array(&quot;Jan&quot;, &quot;Feb&quot;, &quot;Mar&quot;, &quot;Apr&quot;, &quot;May&quot;, &quot;Jun&quot;, &quot;Jul&quot;, &quot;Aug&quot;, &quot;Sep&quot;, &quot;Oct&quot;, &quot;Nov&quot;, &quot;Dec&quot;);
  var date = new Date(), day=date.getDate();
  var today = months[date.getMonth()]+&quot; &quot;+day;
  today += ((day==1)||(day==21)||(day==31))?(&quot;st&quot;):(((day==2)||(day==22))?(&quot;nd&quot;):(((day==3)||(day==23))?(&quot;rd&quot;):(&quot;th&quot;)));
  today += &quot;, &quot;+date.getFullYear();
  spnDate.innerHTML = today;
}
</script>
...
<body onload=&quot;setToday();&quot;>
...
<span id=&quot;spnDate&quot;></span>
This will print the current date as
Code:
    Jun 12th, 2001
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top