Coffeescript-date-gettimezoneoffset

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

CoffeeScriptの日付-getTimezoneOffset()

説明

  • getTimezoneOffset()*メソッドは、現在のロケールのタイムゾーンオフセットを分単位で返します。 タイムゾーンオフセットは差の分で、グリニッジ標準時(GMT)は現地時間を基準にしています。

たとえば、タイムゾーンがGMT + 10の場合、-600が返されます。 夏時間のため、この値は一定になりません。

構文

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

Date. getTimezoneOffset()

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

dt = new Date "February 19, 2016 23:15:25:22"
console.log "The time zone offset value of the specified date is : " + dt.getTimezoneOffset()
  • コマンドプロンプト*を開き、以下に示すように.coffeeファイルをコンパイルします。
c:\> coffee -c date_ gettimezoneoffset.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 zone offset value of the specified date is : " + dt.getTimezoneOffset());

}).call(this);

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

c:\> coffee date_ gettimezoneoffset.coffee

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

The time zone offset value of the specified date is : -330