ホーム > Date > getMonth

getMonth

地方時に基づき,日付の「月」を返します.

シンタックス

dateObject.getMonth()

解説

getMonthメソッドは地方時に基づき,0から11までの数字を返します.
(1月は0に,2月は1に,・・・,12月は11になります.)

サンプルコード

以下にgetMonthメソッドを使用したサンプルコードを示します.

<html>
  <head>
    <title>getMonthメソッドのサンプルコード</title>
  </head>
  <body>
    <script type="text/javascript" language="javascript">
      /* 本日日付 (2009/10/08 22:10:15) */
      var now = new Date();
      document.write(now.getMonth() + "<br />");

      /* 1950/10/02 23:59:59*/
      var dt = new Date("October 2, 1950 23:59:59");
      document.write(dt.getMonth() + "<br />");
    </script>
  </body>
</html>

実行例

サンプルコードの実行結果は以下のようになります.

9
9

関連項目

スポンサード リンク

inserted by FC2 system