blob: d2b6ed83d775a3fe33412aa3b1a1b6641c5283d4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
---
title: Date.prototype.getTimezoneOffset()
slug: Web/JavaScript/Reference/Global_Objects/Date/getTimezoneOffset
tags:
- Date
- JavaScript
- Method
- Prototype
- Reference
translation_of: Web/JavaScript/Reference/Global_Objects/Date/getTimezoneOffset
---
<div>{{JSRef}}</div>
<p><strong><code>getTimezoneOffset()</code></strong> メソッドは、 (ホストシステム上における) 現在のロケールから協定世界時 (UTC) までのタイムゾーンの差を分単位で返します。</p>
<div>{{EmbedInteractiveExample("pages/js/date-gettimezoneoffset.html")}}</div>
<div class="hidden">このデモのソースファイルは GitHub リポジトリに格納されています。デモプロジェクトに協力したい場合は、 <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples</a> をクローンしてプルリクエストを送信してください。</div>
<h2 id="Syntax" name="Syntax">構文</h2>
<pre class="syntaxbox notranslate"><var>dateObj</var>.getTimezoneOffset()</pre>
<h3 id="Return_value" name="Return_value">返値</h3>
<p>ホストシステム上の現在の日付から協定世界時 (UTC) までの分単位のタイムゾーンオフセットを表す数値です。</p>
<h2 id="Description" name="Description">解説</h2>
<p>タイムゾーンオフセットは、地方時から協定世界時 (UTC) までの間の分単位の差です。</p>
<p>このオフセットは、地方時が UTC より遅れている時刻の場合は正の数になり、進んでいる時刻の場合は負の数になることを意味します。例えば、タイムゾーンが UTC+10:00(オーストラリア東部標準時、ロシアのウラジオストク時、チャモロ標準時)の場合、-600 が返されます。</p>
<table class="standard-table">
<thead>
<tr>
<th scope="row">現在のロケール</th>
<th scope="col">UTC-8</th>
<th scope="col">UTC</th>
<th scope="col">UTC+3</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">返値</th>
<td>480</td>
<td>0</td>
<td>-180</td>
</tr>
</tbody>
</table>
<p>返されるタイムゾーンオフセットは呼ばれた Date で適用されているものです。</p>
<p>ホストシステムで夏時間が設定されている場合、Date が表す日時と夏時間が適用される日時によって、オフセットが変わります。</p>
<h2 id="Examples" name="Examples">例</h2>
<h3 id="Using_getTimezoneOffset" name="Using_getTimezoneOffset">getTimezoneOffset() の使用</h3>
<pre class="brush: js notranslate">// Get current timezone offset for host device
let x = new Date();
let currentTimeZoneOffsetInHours = x.getTimezoneOffset() / 60;
// 1
// Get timezone offset for International Labour Day (May 1) in 2016
// Be careful, the Date() constructor uses 0-indexed months, so May is
// represented with 4 (and not 5)
let labourDay = new Date(2016, 4, 1)
let labourDayOffset = labourDay.getTimezoneOffset() / 60;
</pre>
<h2 id="Specifications" name="Specifications">仕様書</h2>
<table class="standard-table">
<thead>
<tr>
<th scope="col">仕様書</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{SpecName('ESDraft', '#sec-date.prototype.gettimezoneoffset', 'Date.prototype.getTimezoneOffset')}}</td>
</tr>
</tbody>
</table>
<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2>
<p>{{Compat("javascript.builtins.Date.getTimezoneOffset")}}</p>
<h2 id="See_also" name="See_also">関連情報</h2>
<ul>
<li>{{jsxref("Date")}}</li>
</ul>
|