Skip to content

Instantly share code, notes, and snippets.

@Takazudo
Created October 19, 2014 06:06
Show Gist options
  • Save Takazudo/c91e6f753a0d6fb8e1ed to your computer and use it in GitHub Desktop.
Save Takazudo/c91e6f753a0d6fb8e1ed to your computer and use it in GitHub Desktop.
calender generator
<script type="text/javascript"><!--
function doCal(xxx) {
var now = new Date();
now.setMonth(xxx-1);
var year = now.getFullYear();
var month = now.getMonth() + 1;
var today = now.getDate();
now.setDate(1);
var startDay = now.getDay();
var monthdays = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
var dateMax = monthdays[month - 1];
if (month == 2 && ((year%4 == 0 && year%100 != 0) || year%400 == 0))
dateMax = 29;
var days = new Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
document.write("<table>");
document.write("<tr><th>" + days[0] + "</th>");
for (i=1; i<6; i++) document.write("<th>" + days[i] + "</th>");
console.log('hoge');
document.write("<th bgcolor='#add8e6'>" + days[6] + "</th></tr>\n");
var col=0;
if (startDay > 0) {
document.write("<tr>");
for ( ; col<startDay; col++) document.write("<td>&nbsp;</td>");
}
for (i=1; i<=dateMax; i++) {
if (col == 0) document.write("<tr>");
if (i == today) document.write("<td bgcolor='#ffc3ce'>" + i + "</td>");
else document.write("<td>" + i + "</td>");
if (col == 6) { document.write("</tr>\n"); col=0; } else col++;
}
if (col != 0) {
for ( ; col<7; col++) document.write("<td>&nbsp;</td>");
document.write("</tr>");
}
document.write("</table>");
}
for(var j=1; j<=12; j+=1) {
console.log(j);
doCal(j);
}
//-->
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment