JavaScript: Today's Date
OK, it should be simple, but I keep having to look it up. J The following was compiled from these two sources:
<script type="text/javascript">
function getTodaysDate() {
var curdate = new Date()
// Get the day of the week as a value from 0 to 6
var weekday=new Array(7);
weekday[0]="Sunday";
weekday[1]="Monday";
weekday[2]="Tuesday";
weekday[3]="Wednesday";
weekday[4]="Thursday";
weekday[5]="Friday";
weekday[6]="Saturday";
// Day of the month
var monthname=new Array(12);
monthname[0]="January";
monthname[1]="February";
monthname[2]="March";
monthname[3]="April";
monthname[4]="May";
monthname[5]="June";
monthname[6]="July";
monthname[7]="August";
monthname[8]="September";
monthname[9]="October";
monthname[10]="November";
monthname[11]="December";
var dateString = weekday[curdate.getDay()] + ", " + monthname[curdate.getMonth()] + " " + curdate.getDate() + ", " + curdate.getYear()
alert(dateString)
}
</script>
1 Comments:
Dont assign all seperatly, this works:
months = ['Jan,', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dez'];
days= ['Sun', 'Mon', 'Thu', 'Wen', 'Thu', 'Fri', 'Sat'];
Posta un commento
<< Home