カレンダー
<html>
<head>
<title>カレンダー</title>
</head>
<body>
<table border="10" bordercolor="#ff9966" cellpadding="5" cellspacing="0">
<script language="JavaScript">
<!--
today = new Date();
year = today.getFullYear(); // 今日の年
month = today.getMonth() + 1; // 今日の月
date = today.getDate(); // 今日の日
start = new Date(year + "/" + month + "/1");
startday = start.getDay(); // 1日の曜日
days = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
if(month == 2 && (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)) {
days[1]++; // うるう年
}
enddate = days[month - 1]; // 最後の日
document.write('<tr>');
document.write('<td colspan="7" align="center">');
document.write(year, '<span style="font-size:10px">年</span>');
document.write(month, '<span style="font-size:10px">月</span>');
document.write('</td>');
document.write('</tr>');
document.write('<tr>');
document.write('<td align="center" style="font-size:10px;color:red">日</td>');
document.write('<td align="center" style="font-size:10px">月</td>');
document.write('<td align="center" style="font-size:10px">火</td>');
document.write('<td align="center" style="font-size:10px">水</td>');
document.write('<td align="center" style="font-size:10px">木</td>');
document.write('<td align="center" style="font-size:10px">金</td>');
document.write('<td align="center" style="font-size:10px;color:blue">土</td>');
document.write('</tr>');
count = 0;
for(i = 0 ; i < startday ; i++) { // 1日の曜日までの空欄
if(count % 7 == 0) {
document.write('<tr>');
}
document.write('<td> </td>');
++count;
}
for(i = 1 ; i <= enddate ; i++) { // 日付を書き出す
if(count % 7 == 0) {
document.write('<tr>');
}
document.write('<td align="right"');
if(count % 7 == 0) {
document.write(' style="color:red"');
}
if(count % 7 == 6) {
document.write(' style="color:blue"');
}
document.write('>', i, '</td>');
++count;
if(count % 7 == 0) {
document.write('</tr>');
}
}
while(count % 7 != 0) { // 最後の日から土曜までの空欄
document.write('<td> </td>');
++count;
if(count % 7 == 0) {
document.write('</tr>');
}
}
//-->
</script>
</table>
</body>
</html>
〔 実行する 〕