Coffeescript-date-getfullyear

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

CoffeeScriptの日付-getFullYear()

説明

  • getFullYear()*メソッドは、現地時間に従って指定された日付の年を返します。 * getFullYear()*によって返される値は絶対数です。 1000年から9999年の間の日付の場合、getFullYear()は2008などの4桁の数値を返します。

構文

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

getFullYear()

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

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

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

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

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

  console.log("The year the current date object is : " + dt.getFullYear());

}).call(this);

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

c:\> coffee date_getfullyear.coffee

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

The year the current date object is : 2016