View Full Version : Date on page, but not with time
Strider 02-03-2003, 06:51 PM Hi I'm looking for a piece of code to put the date on my webpage the only ones I can find have time date and time. I would just like the date but not in a xx/xx/xx format. I would like it so that it reads :
January 31st 2003
for example.
Thanks :)
CGI Script.net (http://www.cgiscript.net/cgi-script/csNews/csNews.cgi?database=js_info_display%2edb&command=viewone&id=17&op=t) :D
Kaliyoda 02-04-2003, 01:02 PM Here's the one I use - got it from www.kaosweaver.com
In your HEAD section...
<script language="JavaScript">
<!--
function doClock(){ // By Paul Davis - www.kaosweaver.com
var t=new Date(),a=doClock.arguments,str="",i,a1,lang="1";
var month=new Array('January','Jan', 'February','Feb', 'March','Mar', 'April','Apr', 'May','May', 'June','Jun', 'July','Jul', 'August','Aug', 'September','Sep', 'October','Oct', 'November','Nov', 'December','Dec');
var tday= new Array('Sunday','Sun','Monday','Mon', 'Tuesday','Tue', 'Wednesday','Wed','Thursday','Thr','Friday','Fri', 'Saturday','Sat');
for(i=0;i<a.length;i++) {a1=a[i].charAt(1);switch (a[i].charAt(0)) {
case "M":if ((Number(a1)==3) && ((t.getMonth()+1)<10)) str+="0";
str+=(Number(a1)>1)?t.getMonth()+1:month[t.getMonth()*2+Number(a1)];break;
case "D": if ((Number(a1)==1) && (t.getDate()<10)) str+="0";str+=t.getDate();break;
case "Y": str+=(a1=='0')?t.getFullYear():t.getFullYear().toS tring().substring(2);break;
case "W":str+=tday[t.getDay()*2+Number(a1)];break; default: str+=unescape(a[i]);}}return str;
}
</script>
In your BODY section, where you want to display the date...
<script language="JavaScript">
document.write(doClock("M0","%20","D1",",%20","Y0"));</script>
Works pretty well for me.
Kaliyoda 02-04-2003, 01:10 PM Ooooops! Just read the bit about not posting scripts you didn't write!
Sorry MODS!!!!
Is this ok as I gave the source & link to the website?
If not please accept my appologies & delete it.
lefty 02-04-2003, 02:17 PM Quite all right, how else would we share information? Unless we're a bunch of javascript gurus around here, which I know I'm not. :P Of course if you took credit for writing it, that's another thing. But no worries. :)
Kaliyoda 02-04-2003, 02:23 PM Thanks - just didn't want to drop the ball so soon after signing up!
Strider 02-04-2003, 09:04 PM Thanks guys I will try these out now!. :)
epolady 02-04-2003, 09:43 PM This (http://www.j-scripts.com/scripts/script019.phtml) seems pretty easy, just cut & paste. Date will show up like
Tuesday, February 4
no year though..
whammy 02-08-2003, 12:42 AM <script type="text/javascript">
<!--
var monthname = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
var weekdayname = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
var mydate = new Date();
var myday = mydate.getDay();
var mymonth = mydate.getMonth();
var mydayno = mydate.getDate();
var dateext = "th"
if(mydayno == 1 || mydayno == 21 || mydayno == 31){
dateext = "st";
}
else if(mydayno == 2 || mydayno == 22){
dateext = "nd";
}
else if(mydayno == 3 || mydayno == 23){
dateext = "rd";
}
var myyear = ((mydate.getYear() < 100) ? "19" : "") + mydate.getYear();
var clientdate = weekdayname[myday] + ", "+ monthname[mymonth] + " "+ mydayno + dateext + ", "+ myyear;
// -->
</script>
Put the above in your <head> section. In your webpage use this:
<script type="text/javascript">
<!--
document.write(clientdate);
// -->
</script>
|