Coffeescript-date-gethours

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

CoffeeScript Date-getHours()

説明

  • getHours()*メソッドは、ローカル時間に従って指定された日付の時間を返します。 getHours()によって返される値は、0〜23の整数です。

構文

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

getHours()

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

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

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

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

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

  console.log("The hour value in the current date object is : " + dt.getHours());

}).call(this);

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

c:\> coffee date_gethours.coffee

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

The hour value in the current date object is : 23