Coffeescript-date-gettime

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

CoffeeScriptの日付-getTime()

説明

  • getTime()*メソッドは、世界時に従って指定された日付の時間に対応する数値を返します。 getTimeメソッドによって返される値は、1970年1月1日00:00:00からのミリ秒数です。

構文

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

Date.getTime()

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

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

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

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

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

  console.log("The time in the specified date is : " + dt.getTime());

}).call(this);

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

c:\> coffee date_ gettime.coffee

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

The time in the specified date is : 1455903925022