目录

Time Zone Setting

Use Cases

The local time of different countries and regions varies according to their longitude. Therefore, different time zones are planned. For example, the UK uses time zone 0 and China uses time zone GMT+8. The time in China is eight hours ahead of that in the UK. For example, 12:00 in Beijing is 4 a.m. in London. The time zone module allows your application to obtain the time zone list to implement its own service logic, for example, a dual-clock application.

Since API version 20, the time zone module also supports obtaining the time zone transition time and offset. For details about the time zone transition logic, see DST Transition.

Available APIs

The following table describes the key APIs of the time zone module. For details about the APIs, see @ohos.i18n (Internationalization).

Name Description
getTimeZone(zoneID?: string): TimeZone Obtains the TimeZone object corresponding to the specified time zone ID.
getID(): string Obtains the ID of the TimeZone object.
getDisplayName(locale?: string, isDST?: boolean): string Obtains time zone display name in the specified language.
getRawOffset(): number Obtains the fixed offset of the TimeZone object.
getOffset(date?: number): number Obtains the offset of the specified time zone at the specified time.
getAvailableIDs(): Array<string> Obtains the list of time zone IDs supported by the system.
getAvailableZoneCityIDs(): Array<string> Obtains the list of time zone city IDs supported by the system.
getCityDisplayName(cityID: string, locale: string): string Obtains time zone city display name in the specified language.
getTimezoneFromCity(cityID: string): TimeZone Creates a TimeZone object based on the specified city ID.
getTimezonesByLocation(longitude: number, latitude: number): Array<TimeZone> Obtains the array of TimeZone objects based on the specified geographic coordinates.
getZoneRules(): ZoneRules Obtains the time zone transition rule.
nextTransition(date?: number): ZoneOffsetTransition Obtains the nextTransition object for the specified time.
getMilliseconds(): number Obtains the timestamp of the time zone transition.
getOffsetAfter(): number Obtains the offset after the time zone transition.
getOffsetBefore(): number Obtains the offset before the time zone transition.

How to Develop

[h2]Using Basic Functions

  1. Import the required module.

    import { i18n } from '@kit.LocalizationKit';
  2. Usage scenarios.