Coffeescript-date-getutchours

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

CoffeeScript Date-getUTCHours()

説明

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

構文

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

Date.getUTCHours()

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

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

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

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

  dt = new Date();

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

}).call(this);

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

c:\> coffee date_getutchours.coffee

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

The UTC hours in the specified date is : 17