12e5b6d6dSopenharmony_ci--- 22e5b6d6dSopenharmony_cilayout: default 32e5b6d6dSopenharmony_cititle: TimeZone Classes 42e5b6d6dSopenharmony_cinav_order: 3 52e5b6d6dSopenharmony_ciparent: Date/Time 62e5b6d6dSopenharmony_ci--- 72e5b6d6dSopenharmony_ci<!-- 82e5b6d6dSopenharmony_ci© 2020 and later: Unicode, Inc. and others. 92e5b6d6dSopenharmony_ciLicense & terms of use: http://www.unicode.org/copyright.html 102e5b6d6dSopenharmony_ci--> 112e5b6d6dSopenharmony_ci 122e5b6d6dSopenharmony_ci# ICU TimeZone Classes 132e5b6d6dSopenharmony_ci{: .no_toc } 142e5b6d6dSopenharmony_ci 152e5b6d6dSopenharmony_ci## Contents 162e5b6d6dSopenharmony_ci{: .no_toc .text-delta } 172e5b6d6dSopenharmony_ci 182e5b6d6dSopenharmony_ci1. TOC 192e5b6d6dSopenharmony_ci{:toc} 202e5b6d6dSopenharmony_ci 212e5b6d6dSopenharmony_ci--- 222e5b6d6dSopenharmony_ci 232e5b6d6dSopenharmony_ci## Overview 242e5b6d6dSopenharmony_ci 252e5b6d6dSopenharmony_ciA time zone is a system that is used for relating local times in different 262e5b6d6dSopenharmony_cigeographical areas to one another. For example, in the United States, Pacific 272e5b6d6dSopenharmony_ciTime is three hours earlier than Eastern Time; when it's 6 P.M. in San 282e5b6d6dSopenharmony_ciFrancisco, it's 9 P.M. in Brooklyn. To make things simple, instead of relating 292e5b6d6dSopenharmony_citime zones to one another, all time zones are related to a common reference 302e5b6d6dSopenharmony_cipoint. 312e5b6d6dSopenharmony_ci 322e5b6d6dSopenharmony_ciFor historical reasons, the reference point is Greenwich, England. Local time in 332e5b6d6dSopenharmony_ciGreenwich is referred to as Greenwich Mean Time, or GMT. (This is similar, but 342e5b6d6dSopenharmony_cinot precisely identical, to Universal Coordinated Time, or UTC. We use the two 352e5b6d6dSopenharmony_citerms interchangeably in ICU since ICU does not concern itself with either leap 362e5b6d6dSopenharmony_ciseconds or historical behavior.) Using this system, Pacific Time is expressed as 372e5b6d6dSopenharmony_ciGMT-8:00, or GMT-7:00 in the summer. The offset -8:00 indicates that Pacific 382e5b6d6dSopenharmony_ciTime is obtained from GMT by adding -8:00, that is, by subtracting 8 hours. 392e5b6d6dSopenharmony_ci 402e5b6d6dSopenharmony_ciThe offset differs in the summer because of daylight savings time, or DST. At 412e5b6d6dSopenharmony_cithis point it is useful to define three different flavors of local time: 422e5b6d6dSopenharmony_ci 432e5b6d6dSopenharmony_ci* **Standard Time**: 442e5b6d6dSopenharmony_ci Standard Time is local time without a daylight savings time offset. For 452e5b6d6dSopenharmony_ci example, in California, standard time is GMT-8:00; that is, 8 hours before 462e5b6d6dSopenharmony_ci GMT. 472e5b6d6dSopenharmony_ci* **Daylight Savings Time**: 482e5b6d6dSopenharmony_ci Daylight savings time is local time with a daylight savings time offset. 492e5b6d6dSopenharmony_ci This offset is typically one hour, but is sometimes less. In California, 502e5b6d6dSopenharmony_ci daylight savings time is GMT-7:00. Daylight savings time is observed in most 512e5b6d6dSopenharmony_ci non-equatorial areas. 522e5b6d6dSopenharmony_ci* **Wall Time**: 532e5b6d6dSopenharmony_ci Wall time is what a local clock on the wall reads. In areas that observe 542e5b6d6dSopenharmony_ci daylight savings time for part of the year, wall time is either standard 552e5b6d6dSopenharmony_ci time or daylight savings time, depending on the date. In areas that do not 562e5b6d6dSopenharmony_ci observe daylight savings time, wall time is equivalent to standard time. 572e5b6d6dSopenharmony_ci 582e5b6d6dSopenharmony_ci## Time Zones in ICU 592e5b6d6dSopenharmony_ci 602e5b6d6dSopenharmony_ciICU supports time zones through two classes: 612e5b6d6dSopenharmony_ci 622e5b6d6dSopenharmony_ci* **TimeZone**: 632e5b6d6dSopenharmony_ci `TimeZone` is an abstract base class that defines the time zone API. This API 642e5b6d6dSopenharmony_ci supports conversion between GMT and local time. 652e5b6d6dSopenharmony_ci* **SimpleTimeZone**: 662e5b6d6dSopenharmony_ci `SimpleTimeZone` is a concrete subclass of TimeZone that implements the 672e5b6d6dSopenharmony_ci standard time zones used today internationally. 682e5b6d6dSopenharmony_ci 692e5b6d6dSopenharmony_ciTimezone classes are related to `UDate`, the `Calendar` classes, and the 702e5b6d6dSopenharmony_ci`DateFormat` classes. 712e5b6d6dSopenharmony_ci 722e5b6d6dSopenharmony_ci### Timezone Class in ICU 732e5b6d6dSopenharmony_ci 742e5b6d6dSopenharmony_ci`TimeZone` is an abstract base class. It defines common protocol for a hierarchy 752e5b6d6dSopenharmony_ciof classes. This protocol includes: 762e5b6d6dSopenharmony_ci 772e5b6d6dSopenharmony_ci* A programmatic ID, for example, "America/Los_Angeles". This ID is used to 782e5b6d6dSopenharmony_ci call up a specific real-world time zone. It corresponds to the IDs defined 792e5b6d6dSopenharmony_ci in the [IANA Time Zone datbase](https://www.iana.org/time-zones) used by UNIX 802e5b6d6dSopenharmony_ci and other systems, and has the format continent/city or ocean/city. 812e5b6d6dSopenharmony_ci* A raw offset. This is the difference, in milliseconds, between a time zone's 822e5b6d6dSopenharmony_ci standard time and GMT. Positive raw offsets are east of Greenwich. 832e5b6d6dSopenharmony_ci* Factory methods and methods for handling the default time zone. 842e5b6d6dSopenharmony_ci* Display name methods. 852e5b6d6dSopenharmony_ci* An API to compute the difference between local wall time and GMT. 862e5b6d6dSopenharmony_ci 872e5b6d6dSopenharmony_ci#### Factory Methods and the Default Timezone 882e5b6d6dSopenharmony_ci 892e5b6d6dSopenharmony_ciThe TimeZone factory method `createTimeZone()` creates and returns a `TimeZone` 902e5b6d6dSopenharmony_ciobject given a programmatic ID. The user does not know what the class of the 912e5b6d6dSopenharmony_cireturned object is, other than that it is a subclass of `TimeZone`. 922e5b6d6dSopenharmony_ci 932e5b6d6dSopenharmony_ciThe `createAvailableIDs()` methods return lists of the programmatic IDs of all 942e5b6d6dSopenharmony_cizones known to the system. These IDs may then be passed to `createTimeZone()` to 952e5b6d6dSopenharmony_cicreate the actual time zone objects. ICU maintains a comprehensive list of 962e5b6d6dSopenharmony_cicurrent international time zones, as derived from the Olson data. 972e5b6d6dSopenharmony_ci 982e5b6d6dSopenharmony_ci`TimeZone` maintains a static time zone object known as the *default time zone*. 992e5b6d6dSopenharmony_ciThis is the time zone that is used implicitly when the user does not specify 1002e5b6d6dSopenharmony_cione. ICU attempts to match this to the host OS time zone. The user may obtain a 1012e5b6d6dSopenharmony_ciclone of the default time zone by calling `createDefault()` and may change the 1022e5b6d6dSopenharmony_cidefault time zone by calling `setDefault()` or `adoptDefault()`. 1032e5b6d6dSopenharmony_ci 1042e5b6d6dSopenharmony_ci#### Display Name 1052e5b6d6dSopenharmony_ci 1062e5b6d6dSopenharmony_ciWhen displaying the name of a time zone to the user, use the display name, not 1072e5b6d6dSopenharmony_cithe programmatic ID. The display name is returned by the `getDisplayName()` 1082e5b6d6dSopenharmony_cimethod. A time zone may have three display names: 1092e5b6d6dSopenharmony_ci 1102e5b6d6dSopenharmony_ci* Generic name, such as "Pacific Time". 1112e5b6d6dSopenharmony_ci* Standard name, such as "Pacific Standard Time". 1122e5b6d6dSopenharmony_ci* Daylight savings name, such as "Pacific Daylight Time". 1132e5b6d6dSopenharmony_ci 1142e5b6d6dSopenharmony_ciFurthermore, each of these names may be LONG or SHORT. The SHORT form is 1152e5b6d6dSopenharmony_citypically an abbreviation, e.g., "PST", "PDT". 1162e5b6d6dSopenharmony_ci 1172e5b6d6dSopenharmony_ciIn addition to being available directly from the `TimeZone` API, the display name 1182e5b6d6dSopenharmony_ciis used by the date format classes to format and parse time zones. 1192e5b6d6dSopenharmony_ci 1202e5b6d6dSopenharmony_ci#### getOffset() API 1212e5b6d6dSopenharmony_ci 1222e5b6d6dSopenharmony_ci`TimeZone` defines the API `getOffset()` by which the caller can determine the 1232e5b6d6dSopenharmony_cidifference between local time and GMT. This is a pure virtual API, so it is 1242e5b6d6dSopenharmony_ciimplemented in the concrete subclasses of `TimeZone`. 1252e5b6d6dSopenharmony_ci 1262e5b6d6dSopenharmony_ci## Updating the Time Zone Data 1272e5b6d6dSopenharmony_ci 1282e5b6d6dSopenharmony_ciTime zone data changes often in response to governments around the world 1292e5b6d6dSopenharmony_cichanging their local rules and the areas where they apply. ICU derives its tz 1302e5b6d6dSopenharmony_cidata from the [IANA Time Zone Database](http://www.iana.org/time-zones). 1312e5b6d6dSopenharmony_ci 1322e5b6d6dSopenharmony_ciThe ICU project publishes updated timezone resource data in response to IANA 1332e5b6d6dSopenharmony_ciupdates, and these can be used to patch existing ICU installations. Several 1342e5b6d6dSopenharmony_ciupdate strategies are possible, depending on the ICU version and configuration. 1352e5b6d6dSopenharmony_ci 1362e5b6d6dSopenharmony_ci* ICU4J: Use the time zone update utility. 1372e5b6d6dSopenharmony_ci* ICU4C 54 and newer: Drop in the binary update files. 1382e5b6d6dSopenharmony_ci* ICU4C 36 and newer: the best update strategy will depend on how ICU data 1392e5b6d6dSopenharmony_ci loading is configured for the specific ICU installation. 1402e5b6d6dSopenharmony_ci * Data is loaded from a .dat package file: replace the time zone resources 1412e5b6d6dSopenharmony_ci in the .dat file using the icupkg tool. 1422e5b6d6dSopenharmony_ci * Data is loaded from a .dll or .so shared library: obtain the updated 1432e5b6d6dSopenharmony_ci sources for the tz resources and rebuild the data library. 1442e5b6d6dSopenharmony_ci * Data is loaded from individual files: drop in the updated binary .res 1452e5b6d6dSopenharmony_ci files. 1462e5b6d6dSopenharmony_ci 1472e5b6d6dSopenharmony_ciThe [ICU Data](../../icudata.md) section of this user guide gives more 1482e5b6d6dSopenharmony_ciinformation on how ICU loads resources. 1492e5b6d6dSopenharmony_ci 1502e5b6d6dSopenharmony_ciThe ICU resource files required for time zone data updates are posted at 1512e5b6d6dSopenharmony_ci<https://github.com/unicode-org/icu-data/tree/main/tzdata/icunew>. The 1522e5b6d6dSopenharmony_cirequired resource files for ICU version 44 and newer are 1532e5b6d6dSopenharmony_ci 1542e5b6d6dSopenharmony_ci* zoneinfo64.res 1552e5b6d6dSopenharmony_ci* windowsZones.res 1562e5b6d6dSopenharmony_ci* timezoneTypes.res 1572e5b6d6dSopenharmony_ci* metaZones.res 1582e5b6d6dSopenharmony_ci 1592e5b6d6dSopenharmony_ci### ICU4C TZ update of a .dat Package File 1602e5b6d6dSopenharmony_ci 1612e5b6d6dSopenharmony_ciFor ICU configurations that load data from a .dat package file, replace the time 1622e5b6d6dSopenharmony_cizone resources in that file. 1632e5b6d6dSopenharmony_ci 1642e5b6d6dSopenharmony_ci1. Download the new .res files from 1652e5b6d6dSopenharmony_ci `https://github.com/unicode-org/icu-data/tree/main/tzdata/icunew/<IANA tz version>/44/<platform directory>`. 1662e5b6d6dSopenharmony_ci * `<IANA tz version>` is a combination of year and letter, such as "2019c". 1672e5b6d6dSopenharmony_ci * *"44"* is the directory for updates to ICU version 4.4 and newer. 1682e5b6d6dSopenharmony_ci * `<platform directory>` is "le" for little endian processors, including 1692e5b6d6dSopenharmony_ci all Intel processors. 1702e5b6d6dSopenharmony_ci * `<platform directory>` is "be" for big endian processors, including IBM 1712e5b6d6dSopenharmony_ci Power and Sparc. 1722e5b6d6dSopenharmony_ci * `<platform directory>` is "ee" for IBM mainframes using EBCDIC character 1732e5b6d6dSopenharmony_ci sets. 1742e5b6d6dSopenharmony_ci2. Check that the tool "icupkg" is available. If not already on your system, 1752e5b6d6dSopenharmony_ci you can get it by [downloading](https://github.com/unicode-org/icu/releases) 1762e5b6d6dSopenharmony_ci and building ICU, following the instructions in the ReadMe file included in 1772e5b6d6dSopenharmony_ci the download. Alternatively, on many Linux systems, "apt-get install 1782e5b6d6dSopenharmony_ci icu-devtools" will install the tool. 1792e5b6d6dSopenharmony_ci3. Locate the .dat file to be updated, and do the update. The commands below 1802e5b6d6dSopenharmony_ci are for a .dat file named icudt55l.dat. 1812e5b6d6dSopenharmony_ci 1822e5b6d6dSopenharmony_ci```shell 1832e5b6d6dSopenharmony_ciicupkg -a zoneinfo64.res icudt55l.dat 1842e5b6d6dSopenharmony_ciicupkg -a windowsZones.res icudt55l.dat 1852e5b6d6dSopenharmony_ciicupkg -a timezoneTypes.res icudt55l.dat 1862e5b6d6dSopenharmony_ciicupkg -a metaZones.res icudt55l.dat 1872e5b6d6dSopenharmony_ci``` 1882e5b6d6dSopenharmony_ci 1892e5b6d6dSopenharmony_ciIn ICU versions older than 4.4 some of the time zone resources have slightly 1902e5b6d6dSopenharmony_cidifferent names. The update procedure is the same, but substitute the names 1912e5b6d6dSopenharmony_cifound in the desired download directory - 42, 40, 38 or 36. 1922e5b6d6dSopenharmony_ci 1932e5b6d6dSopenharmony_ci### ICU4C TZ Update with Drop-in .res files (ICU 54 and newer) 1942e5b6d6dSopenharmony_ci 1952e5b6d6dSopenharmony_ciWith this approach, the four individual .res files are dropped in any convenient 1962e5b6d6dSopenharmony_cilocation in the file system, and ICU is given an absolute path to the directory 1972e5b6d6dSopenharmony_cicontaining them. For the time zone resources only, ICU will check this directory 1982e5b6d6dSopenharmony_cifirst when loading data. This approach will work even when all other ICU data 1992e5b6d6dSopenharmony_ciloading is from a shared library or .dat file. 2002e5b6d6dSopenharmony_ci 2012e5b6d6dSopenharmony_ciThere are two ways to specify the directory: 2022e5b6d6dSopenharmony_ci 2032e5b6d6dSopenharmony_ci* At ICU build time, by defining the C pre-processor variable 2042e5b6d6dSopenharmony_ci `U_TIMEZONE_FILES_DIR` to the run time path to the directory containing the 2052e5b6d6dSopenharmony_ci .res files. 2062e5b6d6dSopenharmony_ci* At run time, by setting the environment variable `ICU_TIMEZONE_FILES_DIR` to 2072e5b6d6dSopenharmony_ci the absolute path of the directory containing the .res files. 2082e5b6d6dSopenharmony_ci 2092e5b6d6dSopenharmony_ciIf both are defined, the environment variable `ICU_TIMEZONE_FILES_DIR` take 2102e5b6d6dSopenharmony_ciprecedence. If either is defined, the time zone directory will be checked first, 2112e5b6d6dSopenharmony_cimeaning that time zone resource files placed there will override time zone 2122e5b6d6dSopenharmony_ciresources that may exist in other ICU data locations. 2132e5b6d6dSopenharmony_ci 2142e5b6d6dSopenharmony_ciTo do the update, download the .res files appropriate for the platform, as 2152e5b6d6dSopenharmony_cidescribed for the .dat file update above, and copy them into the time zone res 2162e5b6d6dSopenharmony_cifile directory. 2172e5b6d6dSopenharmony_ci 2182e5b6d6dSopenharmony_ci### ICU4C TZ update when ICU is configured for individual files 2192e5b6d6dSopenharmony_ci 2202e5b6d6dSopenharmony_ciIf the ICU-using application sets an ICU data path (or can be changed to set 2212e5b6d6dSopenharmony_cione), then the time zone .res file can be placed there. Download the files as 2222e5b6d6dSopenharmony_cidescribed above and copy them to the specified directory. See the 2232e5b6d6dSopenharmony_ci[ICU Data](../../icudata.md) page of the user guide for more information about 2242e5b6d6dSopenharmony_cithe ICU data path. 2252e5b6d6dSopenharmony_ci 2262e5b6d6dSopenharmony_ci### ICU4C TZ update when ICU data is built into a shared library 2272e5b6d6dSopenharmony_ci 2282e5b6d6dSopenharmony_ci1. Set up the environment necessary to rebuild your specific configuration of 2292e5b6d6dSopenharmony_ci ICU. 2302e5b6d6dSopenharmony_ci2. Download the .txt file sources for the updated resources from 2312e5b6d6dSopenharmony_ci `https://github.com/unicode-org/icu-data/tree/main/tzdata/icunew/<IANA tz version>/44` 2322e5b6d6dSopenharmony_ci3. Copy the downloaded .txt files into the ICU sources for your installation, 2332e5b6d6dSopenharmony_ci in the subdirectory source/data/misc/ 2342e5b6d6dSopenharmony_ci4. Rebuid ICU. 2352e5b6d6dSopenharmony_ci5. Copy the freshly built ICU data shared library to the desired destination. 2362e5b6d6dSopenharmony_ci 2372e5b6d6dSopenharmony_ci> :point_right: **Note**: The standard ICU download package contains pre-built 2382e5b6d6dSopenharmony_ci> ICU data. To rebuild ICU data from .txt files, you will need to replace the 2392e5b6d6dSopenharmony_ci> contents of `icu4c/source/data` with the contents of ICU4C data.zip. See 2402e5b6d6dSopenharmony_ci> [ICU Data Build Tool](../../icu_data/buildtool.md) for more details. 2412e5b6d6dSopenharmony_ci 2422e5b6d6dSopenharmony_ciThere are too many possible platform variations to be more specific about how to 2432e5b6d6dSopenharmony_cirebuild ICU4C in these instructions. See the ReadMe file included with the ICU 2442e5b6d6dSopenharmony_cisources for general information on building ICU. 2452e5b6d6dSopenharmony_ci 2462e5b6d6dSopenharmony_ci### Update the time zone data for ICU4J 2472e5b6d6dSopenharmony_ci 2482e5b6d6dSopenharmony_ciThe [ICU4J Time Zone Update Update 2492e5b6d6dSopenharmony_ciUtility](https://icu.unicode.org/download/icutzu) automates the process of 2502e5b6d6dSopenharmony_ciupdating ICU4J jar files with the latest time zone data. Instructions for use 2512e5b6d6dSopenharmony_ciare [here](https://htmlpreview.github.io/?https://github.com/unicode-org/icu-data/blob/main/tzdata/tzu/readme.html). 2522e5b6d6dSopenharmony_ci 2532e5b6d6dSopenharmony_ciThe updater will work with ICU version 3.4.2 and newer. 2542e5b6d6dSopenharmony_ci 2552e5b6d6dSopenharmony_ci## Sample Code 2562e5b6d6dSopenharmony_ci 2572e5b6d6dSopenharmony_ciSee the [Date and Time Zone Examples](examples.md) subpage. 258