Coffeescript-date-getutcmonth

提供:Dev Guides
移動先:案内検索

CoffeeScriptの日付-getUTCMonth()

説明

  • getUTCMonth()*メソッドは、世界時に従って指定された日付の月を返します。 getUTCMonth()によって返される値は、月に対応する0〜11の整数です。 1月は0、2月は1、3月は2などのようになります。

構文

以下に、* getUTCMonth()*メソッドの構文を示します。

Date.getUTCMonth()

次の例は、CoffeeScriptでの* getUTCMonth()メソッドの使用方法を示しています。 このコードを *date_getutcmonth.coffee という名前のファイルに保存します。

dt = new Date()
console.log "The UTC month in the specified date is : " + dt.getUTCMonth()
  • コマンドプロンプト*を開き、以下に示すように.coffeeファイルをコンパイルします。
c:\> coffee -c date_getutcmonth.coffee

コンパイル時に、次のJavaScriptが提供されます。

//Generated by CoffeeScript 1.10.0
(function() {
  var dt;

  dt = new Date();

  console.log("The UTC month in the specified date is : " + dt.getUTCMonth());

}).call(this);

次に、*コマンドプロンプト*を再度開き、以下に示すようにCoffeeScriptファイルを実行します。

c:\> coffee date_getutcmonth.coffee

CoffeeScriptファイルを実行すると、次の出力が生成されます。

The UTC month in the specified date is : 1