Coffeescript-date-getmonth
提供:Dev Guides
CoffeeScriptの日付-getMonth()
説明
- getMonth()*メソッドは、現地時間に従って指定された日付の月を返します。 getMonth()によって返される値は、0〜11の整数です。 0は1月、1〜2月などに対応します。
構文
以下に、* getMonth()*メソッドの構文を示します。
Date.getMonth()
例
次の例は、CoffeeScriptでの* getMonth()メソッドの使用方法を示しています。 このコードを *date_getmonth.coffee という名前のファイルに保存します。
dt = new Date "February 19, 2016 23:15:25:22"
console.log "The month in the specified date is : " + dt.getMonth()
- コマンドプロンプト*を開き、以下に示すように.coffeeファイルをコンパイルします。
c:\> coffee -c date_ getmonth.coffee
コンパイル時に、次のJavaScriptが提供されます。
//Generated by CoffeeScript 1.10.0
(function() {
var dt;
dt = new Date("February 19, 2016 23:15:25:22");
console.log("The month in the specified date is : " + dt.getMonth());
}).call(this);
次に、*コマンドプロンプト*を再度開き、以下に示すようにCoffeeScriptファイルを実行します。
c:\> coffee date_ getmonth.coffee
CoffeeScriptファイルを実行すると、次の出力が生成されます。
The month in the specified date is : 1