Coffeescript-date-getday

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

CoffeeScriptの日付-getDay()

説明

  • getDay()*メソッドは、ローカル時間に従って指定された日付の曜日を返します。 getDay()によって返される値は、曜日に対応する整数です:日曜日は0、月曜日は1、火曜日は2など。

構文

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

Date.getDay()

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

dt = new Date "February 19, 2016 23:15:00"
console.log "The day of the current date object is : " + dt.getDay()
  • コマンドプロンプト*を開き、以下に示すように.coffeeファイルをコンパイルします。
c:\> coffee -c date_getday.coffee

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

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

  dt = new Date("February 19, 2016 23:15:00");

  console.log("The day of the current date object is : " + dt.getDay());

}).call(this);

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

c:\> coffee date_getday.coffee

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

The day in the current date object is : 5