1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
<script> function getTime() { // initialize time-related variables with current time settings var now = new Date(); var hour = now.getHours(); var minute = now.getMinutes(); now = null; var ampm = ""; // validate hour values and set value of ampm if (hour>= 12) { hour -= 12; ampm = "PM"; } else { ampm = "AM"; } hour = (hour == 0) ? 12 : hour; // add zero digit to a one digit minute if (minute <10) minute = "0" + minute; // do not parse this number! // return time string return hour + ": " + minute + "" + ampm; } function leapYear(year) { if (year % 4 == 0) // basic rule return true; // is leap year return false; // is not leap year } function getDays(month, year) { // create array to hold number of days in each month var ar = new Array(12); ar[0] = 31; // January ar[1] = (leapYear(year)) ? 29 : 28; // February ar[2] = 31; // March ar[3] = 30; // April ar[4] = 31; // May ar[5] = 30; // June ar[6] = 31; // July ar[7] = 31; // August ar[8] = 30; // September ar[9] = 31; // October ar[10] = 30; // November ar[11] = 31; // December // return number of days in the specified month (parameter) return ar[month]; } function getMonthName(month) { // create array to hold name of each month var ar = new Array(12); ar[0] = "01"; ar[1] = "02"; ar[2] = "03"; ar[3] = "04"; ar[4] = "05"; ar[5] = "06"; ar[6] = "07"; ar[7] = "08"; ar[8] = "09"; ar[9] = "10"; ar[10] = "11"; ar[11] = "12"; // return name of specified month (parameter) return ar[month]; } function setCal() { // standard time attributes var now = new Date(); var year = now.getYear(); var month = now.getMonth(); var monthName = getMonthName(month); var date = now.getDate(); now = null; // create instance of first day of month, and extract the day on which it occurs var firstDayInstance = new Date(year, month, 1); var firstDay = firstDayInstance.getDay(); firstDayInstance = null; // number of days in current month var days = getDays(month, year); // call function to draw calendar drawCal(firstDay + 1, days, date, monthName, year); } function drawCal(firstDay, lastDate, date, monthName, year) { var tableScript = ""; tableScript += "<table border='0' cellpadding='2' cellspacing='0' width=100% bordercolordark='#ffffff'>" tableScript += " <tr>" tableScript += " <td align='center'></td>" tableScript += " </tr>" tableScript += " <tr>" tableScript += " <td>" tableScript += " <table width='100%' align=center border='0' cellspacing='2' cellpadding='0'>" tableScript += " <tr>" tableScript += " <td>日</td>" tableScript += " <td>一</td>" tableScript += " <td>二</td>" tableScript += " <td>三</td>" tableScript += " <td>四</td>" tableScript += " <td>五</td>" tableScript += " <td>六</td>" tableScript += " </tr>" var digit = 1; var curCell = 1; var day = ""; for (var row = 1; row <= Math.ceil((lastDate + firstDay-1) / 7); ++row) { tableScript += "<tr align = 'right'valign = 'top'> " for (var col = 1; col <= 7; ++col) { if (digit> lastDate) break; if (curCell <firstDay) { tableScript += " <td> </td>"; curCell++; } else { if (digit <10) day = year + '-' + monthName + '-0' + digit; else day = year + '-' + monthName + '-' + digit; if (digit == date) { // current cell represent today's date tableScript += " <td align = center> "; tableScript += " <a HREF = 'showproduct.asp ? day = " + day + "'> " + " <font color = 'red'> <b> " + digit + " </b></font> </a>"; tableScript += "</td> "; } else tableScript += " <td align = center> <a HREF = 'showproduct.asp ? day = " + day + "'> " + digit + " </a></td>"; digit++; } } tableScript += " </tr>" }; tableScript += " "; tableScript += " </table> "; tableScript += " </td>"; tableScript += " </tr> "; tableScript += " </table>"; document.write(tableScript); } setCal(); </script> |