View Full Version : Any javascript guru's?
I need a code that will disply the current date of the server in this format:
October 7, 2001
Anyone can help?
Thanks,
Steve
Unknown
10-06-2001, 11:47 PM
<SCRIPT language="JavaScript"><!--
<!-- Begin
var day="";
var month="";
var ampm="";
var ampmhour="";
var myweekday="";
var year="";
mydate = new Date();
myday = mydate.getDay();
mymonth = mydate.getMonth();
myweekday= mydate.getDate();
weekday= myweekday;
myyear= mydate.getYear();
myhours = mydate.getHours();
ampmhour = (myhours > 12) ? myhours - 12 : myhours;
ampm = (myhours >= 12) ? 'PM' : 'AM';
mytime = mydate.getMinutes();
myminutes = ((mytime < 10) ? ':0' : ':') + mytime;
year = (myyear > 100) ? myyear : 1900 + myyear;
if(myday ==0)
day = " Sunday, ";
else if(myday == 1)
day = " Monday, ";
else if(myday == 2)
day = " Tuesday, ";
else if(myday == 3)
day = " Wednesday, ";
else if(myday == 4)
day = " Thursday, ";
else if(myday == 5)
day = " Friday, ";
else if(myday == 6)
day = " Saturday, ";
if(mymonth == 0) {
month = "January ";}
else if(mymonth ==1)
month = "February ";
else if(mymonth ==2)
month = "March ";
else if(mymonth ==3)
month = "April ";
else if(mymonth ==4)
month = "May ";
else if(mymonth ==5)
month = "June ";
else if(mymonth ==6)
month = "July ";
else if(mymonth ==7)
month = "August ";
else if(mymonth ==8)
month = "September ";
else if(mymonth ==9)
month = "October ";
else if(mymonth ==10)
month = "November ";
else if(mymonth ==11)
month = "December ";
// End -->
</SCRIPT>
<SCRIPT LANGUAGE="JavaScript"><!-- Begin
var nn = navigator.appName;
var nnv = parseInt(navigator.appVersion)
if((nn == "Netscape") && (nnv < 4)){
}
else{
document.write("<span class=date>" + day + month + myweekday + ", " + year +
"</span>");
}
// End -->
</SCRIPT>
Unknown
10-06-2001, 11:52 PM
This one is shorter and better. Displays the date in the format you supplied.
<script language="JavaScript1.2">
<!--
var months=new Array(13);
months[1]="January";
months[2]="February";
months[3]="March";
months[4]="April";
months[5]="May";
months[6]="June";
months[7]="July";
months[8]="August";
months[9]="September";
months[10]="October";
months[11]="November";
months[12]="December";
var time=new Date();
var lmonth=months[time.getMonth() + 1];
var date=time.getDate();
var year=time.getYear();
if (year < 2000)
year = year + 1900;
document.write(" " + lmonth + " ");
document.write(date + ", " + year + " ");
-->
</script>
salsbury
10-07-2001, 12:06 PM
note that javascript Date() can only know the date of the clock on the web browser's machine, not the one on your server. judging by e-mail headers i've seen from people, maybe 20% of the internet's clocks are way off. :)
vBulletin® v3.7.3, Copyright ©2000-2012, Jelsoft Enterprises Ltd.