20
20
<methodparam choice =" opt" ><type >int</type ><parameter >timezoneGroup</parameter ><initializer >DateTimeZone::ALL</initializer ></methodparam >
21
21
<methodparam choice =" opt" ><type class =" union" ><type >string</type ><type >null</type ></type ><parameter >countryCode</parameter ><initializer >&null; </initializer ></methodparam >
22
22
</methodsynopsis >
23
+ <para >
24
+ Return the list of <link xlink : href =" https://en.wikipedia.org/wiki/Tz_database#Names_of_timezones" >IANA Time Zone identifiers</link >.
25
+ </para >
26
+
27
+ <note >
28
+ <para >
29
+ It's possible to detect the client (browser) timezone with JavaScript using
30
+ <link xlink : href =" https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/resolvedOptions#timezone" >Intl.DateTimeFormat</link >
31
+ or <link xlink : href =" https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/ZonedDateTime#time_zones_and_offsets" >Temporal.ZonedDateTime</link >.
32
+ </para >
33
+ </note >
34
+
23
35
</refsect1 >
24
36
25
37
<refsect1 role =" parameters" >
96
108
&reftitle.examples;
97
109
<para >
98
110
<example >
99
- <title >A < methodname >DateTimeZone::listIdentifiers</ methodname > example </title >
100
- <programlisting role =" php" >
111
+ <title >List identifiers with location comments </title >
112
+ <programlisting role =" php" annotations = " interactive " >
101
113
<![CDATA[
102
114
<?php
103
- $timezone_identifiers = DateTimeZone::listIdentifiers();
104
- for ($i=0; $i < 5; $i++) {
105
- echo "$timezone_identifiers[$i]\n";
115
+ $identifiers = DateTimeZone::listIdentifiers(DateTimeZone::ALL);
116
+
117
+ foreach ($identifiers as $tzid) {
118
+ $tz = new DateTimeZone($tzid);
119
+ $comments = $tz->getLocation()['comments'];
120
+ echo $tzid . " (" . ($comments ?: 'Whole region') . ")\n";
106
121
}
107
- ?>
108
122
]]>
109
123
</programlisting >
110
124
&example.outputs.similar;
111
125
<screen >
112
126
<![CDATA[
113
- Africa/Abidjan
114
- Africa/Accra
115
- Africa/Addis_Ababa
116
- Africa/Algiers
117
- Africa/Asmara
127
+ // (Output omitted due to length)
128
+ America/Antigua (Whole region)
129
+ America/Araguaina (Tocantins)
130
+ America/Argentina/Buenos_Aires (Buenos Aires (BA, CF))
131
+ America/Argentina/Catamarca (Catamarca (CT), Chubut (CH))
132
+ America/Argentina/Cordoba (Argentina (most areas: CB, CC, CN, ER, FM, MN, SE, SF))
133
+ // (Output omitted due to length)
118
134
]]>
119
135
</screen >
120
136
</example >
@@ -123,14 +139,13 @@ Africa/Asmara
123
139
<para >
124
140
<example >
125
141
<title >Listing identifiers for a specific region</title >
126
- <programlisting role =" php" >
142
+ <programlisting role =" php" annotations = " interactive " >
127
143
<![CDATA[
128
144
<?php
129
145
$timezone_identifiers = DateTimeZone::listIdentifiers( DateTimeZone::ASIA );
130
146
for ($i=0; $i < 5; $i++) {
131
147
echo "$timezone_identifiers[$i]\n";
132
148
}
133
- ?>
134
149
]]>
135
150
</programlisting >
136
151
&example.outputs.similar;
@@ -149,12 +164,11 @@ Asia/Aqtau
149
164
<para >
150
165
<example >
151
166
<title >Listing identifiers for multiple regions</title >
152
- <programlisting role =" php" >
167
+ <programlisting role =" php" annotations = " interactive " >
153
168
<![CDATA[
154
169
<?php
155
170
$timezone_identifiers = DateTimeZone::listIdentifiers( DateTimeZone::ASIA | DateTimeZone::PACIFIC );
156
171
echo join( ', ', $timezone_identifiers );
157
- ?>
158
172
]]>
159
173
</programlisting >
160
174
&example.outputs.similar;
@@ -194,14 +208,13 @@ Pacific/Tarawa, Pacific/Tongatapu, Pacific/Wake, Pacific/Wallis
194
208
<para >
195
209
<example >
196
210
<title >Listing identifiers for a single country</title >
197
- <programlisting role =" php" >
211
+ <programlisting role =" php" annotations = " interactive " >
198
212
<![CDATA[
199
213
<?php
200
214
$timezone_identifiers = DateTimeZone::listIdentifiers( DateTimeZone::PER_COUNTRY, "UA" );
201
215
foreach( $timezone_identifiers as $identifier ) {
202
216
echo "$identifier\n";
203
217
}
204
- ?>
205
218
]]>
206
219
</programlisting >
207
220
&example.outputs.similar;
0 commit comments