Jump to content

Formatting the date on my website


Recommended Posts

I have found some excellent javascript code to put today's date on my website. Unfortunately it appears as:This site was updatedTuesday 24thAugust 2010I want it to appear as This site was updated Tuesday 24th August 2010The code that prints out the date is <p>This site was updated <div id="day"> </div> <div id="date"> </div></div></p>I hope someone can help me. Below is all the code in case that helps.Ta.<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html><head><title></title><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><!--<style type="text/css">#container { width:8.6em; padding:1em; border:3px double #999; margin:auto; }#day,#date { font-family:verdana,arial,helvetica,sans-serif; font-size:1em; }</style>--><script type="text/javascript">if(window.addEventListener){ window.addEventListener('load',showDate,false); }else { if(window.attachEvent){ window.attachEvent('onload',showDate); } }function showDate() { months=['January','February','March','April','May','June','July', 'August','September','October','November','December']; days=['Sunday','Monday','Tuesday','Wednesday', 'Thursday','Friday','Saturday']; now=new Date(); yy=now.getUTCFullYear(); mm=now.getUTCMonth(); dt=now.getDate(); dd=now.getUTCDay(); end='th';if((dt==1)||(dt==21)||(dt==31)) { end='st.'; }if((dt==2)||(dt==22)) { end='nd'; }if((dt==3)||(dt==23)) { end='rd'; } document.getElementById('day').firstChild.nodeValue=days[dd]+' '+dt+end; document.getElementById('date').firstChild.nodeValue=months[mm]+', '+yy; }</script></head><body><p>This site was updated <div id="day"> </div> <div id="date"> </div></div></p></body></html>

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

  • Create New...