date()の月の表示
- <!DOCTYPE html>
- <html lang="ja">
- <head>
- <meta charset="UTF-8">
- <title>date()の月の表示</title>
- <style type="text/css">
- th, td
- {
- border:1px solid #ccc;
- text-align:center;
- padding:3px;
- font-size:10pt;
- }
- </style>
- <body>
- <h1>date()の月の表示</h1>
- <script type="text/javascript">
- y=2012;
- m=1;
- d=1;
- document.write("<table>");
- document.write('<tr style="background:#ffddff;">');
- document.write('<td colspan="2">年月</td>');
- document.write('<td colspan="3">ng = new Date(y, m, d)</td>');
- document.write('<td colspan="3"><b>ok1 = new Date(y, m-1, d)</b></td>');
- document.write('<td colspan="3"><b>ok2 = new Date("y/m/d")</b></td>');
- document.write("</tr>");
- document.write('<tr style="background:#ffddff;">');
- document.write("<td>y</td><td>m</td>");
- document.write("<td>ng.getFullYear()</td><td>ng.getMonth()</td><td>ng.getMonth()+1</td>");
- document.write("<td><b>ok1.getFullYear()</b></td><td>ok1.getMonth()</td><td><b>ok1.getMonth()+1</b></td>");
- document.write("<td><b>ok2.getFullYear()</b></td><td>ok2.getMonth()</td><td><b>ok2.getMonth()+1</b></td>");
- document.write("</tr>");
- for (i=0; i<15; i++)
- {
- ng = new Date(y, m, d);
- ok1 = new Date(y, m-1, d);
- ok2 = new Date(y + "/" + m + "/" + d);
-
- document.write("<tr>");
- document.write("<td>" + y + "</td><td>" + m + "</td>");
- document.write("<td>" + ng.getFullYear() + "</td>");
- document.write("<td>" + ng.getMonth() + "</td>");
- document.write("<td>" + (ng.getMonth()+1) + "</td>");
- document.write("<td><b>" + ok1.getFullYear() + "</b></td>");
- document.write("<td>" + ok1.getMonth() + "</td>");
- document.write('<td><b>' + (ok1.getMonth()+1) + "</b></td>");
- document.write("<td><b>" + ok2.getFullYear() + "</b></td>");
- document.write("<td>" + ok2.getMonth() + "</td>");
- document.write('<td><b>' + (ok2.getMonth()+1) + "</b></td>");
- document.write("</tr>");
- m++;
- }
- document.write("</table>");
- </script>
- <div style="font-size:10pt;text-align:right;margin-top:0.5em;">
- <a href="//tips.recatnap.info/" target="_top">PCスキルの小技・忘却防止メモ</a> -
- <a href="//tips.recatnap.info/wiki/" target="_top">PCスキルの小技・忘却防止メモのまとめ(wiki)</a>
- </div>
- <div style="font-size:10pt;text-align:center;margin-top:0.5em;padding:0.5em;border-top:1px solid #ccc;">
- Copyright © 2009 by PCスキルの小技・忘却防止メモ. All rights reserved.
- </div>
- </body>
- </html>