date()の月の表示

  1. <!DOCTYPE html>
  2. <html lang="ja">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>date()の月の表示</title>
  6. <style type="text/css">
  7. th, td
  8. {
  9.   border:1px solid #ccc;
  10.   text-align:center;
  11.   padding:3px;
  12.   font-size:10pt;
  13. }
  14. </style>
  15. <body>
  16. <h1>date()の月の表示</h1>
  17. <script type="text/javascript">
  18. y=2012;
  19. m=1;
  20. d=1;
  21. document.write("<table>");
  22. document.write('<tr style="background:#ffddff;">');
  23. document.write('<td colspan="2">年月</td>');
  24. document.write('<td colspan="3">ng = new Date(y, m, d)</td>');
  25. document.write('<td colspan="3"><b>ok1 = new Date(y, m-1, d)</b></td>');
  26. document.write('<td colspan="3"><b>ok2 = new Date("y/m/d")</b></td>');
  27. document.write("</tr>");
  28. document.write('<tr style="background:#ffddff;">');
  29. document.write("<td>y</td><td>m</td>");
  30. document.write("<td>ng.getFullYear()</td><td>ng.getMonth()</td><td>ng.getMonth()+1</td>");
  31. document.write("<td><b>ok1.getFullYear()</b></td><td>ok1.getMonth()</td><td><b>ok1.getMonth()+1</b></td>");
  32. document.write("<td><b>ok2.getFullYear()</b></td><td>ok2.getMonth()</td><td><b>ok2.getMonth()+1</b></td>");
  33. document.write("</tr>");
  34. for (i=0; i<15; i++)
  35. {
  36.   ng = new Date(y, m, d);
  37.   ok1 = new Date(y, m-1, d);
  38.   ok2 = new Date(y + "/" + m + "/" + d);
  39.   
  40.   document.write("<tr>");
  41.   document.write("<td>" + y + "</td><td>" + m + "</td>");
  42.   document.write("<td>" +  ng.getFullYear() + "</td>");
  43.   document.write("<td>" +  ng.getMonth()    + "</td>");
  44.   document.write("<td>" + (ng.getMonth()+1) + "</td>");
  45.   document.write("<td><b>" +  ok1.getFullYear() + "</b></td>");
  46.   document.write("<td>"    +  ok1.getMonth()    + "</td>");
  47.   document.write('<td><b>' + (ok1.getMonth()+1) + "</b></td>");
  48.   document.write("<td><b>" +  ok2.getFullYear() + "</b></td>");
  49.   document.write("<td>"    +  ok2.getMonth()    + "</td>");
  50.   document.write('<td><b>' + (ok2.getMonth()+1) + "</b></td>");
  51.   document.write("</tr>");
  52.   m++;
  53. }
  54. document.write("</table>");
  55. </script>
  56. <div style="font-size:10pt;text-align:right;margin-top:0.5em;">
  57. <a href="//tips.recatnap.info/" target="_top">PCスキルの小技・忘却防止メモ</a> -
  58. <a href="//tips.recatnap.info/wiki/" target="_top">PCスキルの小技・忘却防止メモのまとめ(wiki)</a>
  59. </div>
  60. <div style="font-size:10pt;text-align:center;margin-top:0.5em;padding:0.5em;border-top:1px solid #ccc;">
  61. Copyright &copy; 2009 by PCスキルの小技・忘却防止メモ. All rights reserved.
  62. </div>
  63. </body>
  64. </html>