Skip to content

Commit a43d949

Browse files
Update README.md
1 parent a44a962 commit a43d949

File tree

1 file changed

+45
-1
lines changed

1 file changed

+45
-1
lines changed

README.md

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,41 @@ for end-user display output only. Do not attempt to use abbreviations when pars
8585

8686
## Methods for listing time zones
8787

88+
### GetDisplayNames
89+
90+
Gets a dictionary of string/string pairs of time zones, where the key is a time zone identifier,
91+
and the value is the localized name of the time zone, as given by the Windows language pack for
92+
the specified language and locale.
93+
94+
This is useful because the values returned by `TimeZoneInfo.DisplayName` are only localized by the
95+
_operating system's_ language, whereas `TZNames.GetDisplayNames` will work with any supported language.
96+
97+
```csharp
98+
var displayNames = TZNames.GetDisplayNames("fr-CA");
99+
```
100+
*Output*
101+
Key | Value
102+
-------------------------------|--------------------------
103+
Dateline Standard Time | (UTC-12:00) Ligne de date internationale (Ouest)
104+
UTC-11 | (UTC-11:00) Temps universel coordonné-11
105+
Aleutian Standard Time | (UTC-10:00) Îles Aléoutiennes
106+
Hawaiian Standard Time | (UTC-10:00) Hawaii
107+
Marquesas Standard Time | (UTC-09:30) Îles Marquises
108+
Alaskan Standard Time | (UTC-09:00) Alaska
109+
UTC-09 | (UTC-09:00) Temps universel coordonné-09
110+
Pacific Standard Time (Mexico) | (UTC-08:00) Basse Californie
111+
UTC-08 | (UTC-08:00) Temps universel coordonné-08
112+
Pacific Standard Time | (UTC-08:00) Pacifique (É.-U. et Canada)
113+
... | ...
114+
115+
Optionally, you can pass `true` as a second parameter to return IANA time zone IDs as the keys,
116+
though the list will still be limited to valid Windows time zones. When doing so, if there is a
117+
country code in the locale (eg. the `CA` in `fr-CA`) that code will be used as the territory code
118+
in the Windows to IANA mapping.
119+
88120
### GetTimeZonesForCountry
89121

90-
Get a list of time zone names for a specific country, suitable for user time zone
122+
Gets a list of time zone names for a specific country, suitable for user time zone
91123
selection.
92124

93125
Returns a dictionary whose key is the IANA time zone identifier, and whose value
@@ -217,6 +249,18 @@ TODO: Add examples for this method.
217249

218250
## Additional supporting methods
219251

252+
### GetDisplayNameForTimeZone
253+
254+
```csharp
255+
string displayName = TZNames.GetDisplayNameForTimeZone("America/Vancouver", "fr");
256+
// => "(UTC-08:00) Pacifique (É.-U. et Canada)"
257+
```
258+
259+
```csharp
260+
string displayName = TZNames.GetDisplayNameForTimeZone("India Standard Time", "zh-CN");
261+
// => "(UTC+05:30) 钦奈,加尔各答,孟买,新德里"
262+
```
263+
220264
### GetCountryNames
221265

222266
Gets a localized list of country names, suitable for selecting a country before

0 commit comments

Comments
 (0)