timezone.h
Overview
Provides the capability of obtaining time zone information.
Header file: <i18n/timezone.h>
Library: libohi18n.so
System capability: SystemCapability.Global.I18n
Since: 22
Related module: i18n
Summary
Structs
| Name | typedef Keyword | Description |
|---|---|---|
| DateTimeRule | DateTimeRule | Rule of time and date. |
| InitialTimeZoneRule | InitialTimeZoneRule | Start time zone rule. |
| TimeArrayTimeZoneRule | TimeArrayTimeZoneRule | Time zone rule defined by the start timestamp array. |
| AnnualTimeZoneRule | AnnualTimeZoneRule | Time zone rule that takes effect annually. |
| TimeZoneRules | TimeZoneRules | Complete time zone rule. |
| TimeZoneRuleQuery | TimeZoneRuleQuery | Used to input the query information and receive the query result. |
Enums
| Name | typedef Keyword | Description |
|---|---|---|
| DateRuleType | DateRuleType | Enumerates the date rule types. |
| TimeRuleType | TimeRuleType | Enumerates the time rule types. |
Macros
| Name | Description |
|---|---|
| MAX_YEAR_IN_ANNUAL_TIMEZONE_RULE 0x7fffffff | Max year of the time zone rule that takes effect annually. Since: 22 |
Functions
Enum Description
DateRuleType
enum DateRuleType
Description
Enumerates the date rule types.
System capability: SystemCapability.Global.I18n
Since: 22
| Value | Description |
|---|---|
| DOM = 0 | Day of the month. For example, October 16 in 2025 is the 16th day of October. |
| DOW = 1 | Week day of the month. For example, October 16 in 2025 is the third Thursday of October. |
| DOW_GEQ_DOM = 2 | First weekday after the specified day of the month. For example, October 16 in 2025 is the first Thursday after the 13th, 14th, or 15th day of October. |
| DOW_LEQ_DOM = 3 | Last weekday before the specified day of the month. For example, October 16 in 2025 is the last Thursday before the 20th day of October. |
TimeRuleType
enum TimeRuleType
Description
Enumerates the time rule types.
System capability: SystemCapability.Global.I18n
Since: 22
| Value | Description |
|---|---|
| WALL_TIME = 0 | Local clock time (not subject to time zone offset). |
| STANDARD_TIME = 1 | Local standard time (not subject to DST offset). |
| UTC_TIME = 2 | World standard time (UTC time). |
Function Description
OH_i18n_GetTimeZoneRules()
I18n_ErrorCode OH_i18n_GetTimeZoneRules(const char* timeZoneID, TimeZoneRules* rules)
Description
Obtains the complete time zone rule based on the time zone ID.
System capability: SystemCapability.Global.I18n
Since: 22
Parameters
| Name | Description |
|---|---|
| const char* timeZoneID | Time zone ID, for example, Asia/Shanghai. |
| TimeZoneRules* rules | Obtains the complete time zone rule TimeZoneRules corresponding to the time zone ID. |
Returns
| Type | Description |
|---|---|
| I18n_ErrorCode | 0: Success. 8900001: Invalid input parameters. 8900050: Unexpected error, for example, memory error. |
OH_i18n_GetFirstStartFromTimeArrayTimeZoneRule()
I18n_ErrorCode OH_i18n_GetFirstStartFromTimeArrayTimeZoneRule(TimeArrayTimeZoneRule* rule, TimeZoneRuleQuery* query)
Description
Obtains the first effective time of the time zone rule based on TimeArrayTimeZoneRule.
System capability: SystemCapability.Global.I18n
Since: 22
Parameters
| Name | Description |
|---|---|
| TimeArrayTimeZoneRule* rule | Time zone rule TimeArrayTimeZoneRule defined by the start timestamp array. |
| TimeZoneRuleQuery* query | Used to input the query information and receive the query result. |
Returns
| Type | Description |
|---|---|
| I18n_ErrorCode | 0: Success. 8900001: Invalid input parameters. 8900050: Unexpected error, for example, memory error. |
OH_i18n_GetFirstStartFromAnnualTimeZoneRule()
I18n_ErrorCode OH_i18n_GetFirstStartFromAnnualTimeZoneRule(AnnualTimeZoneRule* rule, TimeZoneRuleQuery* query)
Description
Obtains the first effective time of the time zone rule based on AnnualTimeZoneRule.
System capability: SystemCapability.Global.I18n
Since: 22
Parameters
| Name | Description |
|---|---|
| AnnualTimeZoneRule* rule | Time zone rule AnnualTimeZoneRule that takes effect every year. |
| TimeZoneRuleQuery* query | Used to input the query information and receive the query result. |
Returns
| Type | Description |
|---|---|
| I18n_ErrorCode | 0: Success. 8900001: Invalid input parameters. 8900050: Unexpected error, for example, memory error. |
OH_i18n_GetFinalStartFromTimeArrayTimeZoneRule()
I18n_ErrorCode OH_i18n_GetFinalStartFromTimeArrayTimeZoneRule(TimeArrayTimeZoneRule* rule, TimeZoneRuleQuery* query)
Description
Obtains the last effective time of the time zone rule based on TimeArrayTimeZoneRule.
System capability: SystemCapability.Global.I18n
Since: 22
Parameters
| Name | Description |
|---|---|
| TimeArrayTimeZoneRule* rule | Time zone rule TimeArrayTimeZoneRule defined by the start timestamp array. |
| TimeZoneRuleQuery* query | Used to input the query information and receive the query result. |
Returns
| Type | Description |
|---|---|
| I18n_ErrorCode | 0: Success. 8900001: Invalid input parameters. 8900050: Unexpected error, for example, memory error. |
OH_i18n_GetFinalStartFromAnnualTimeZoneRule()
I18n_ErrorCode OH_i18n_GetFinalStartFromAnnualTimeZoneRule(AnnualTimeZoneRule* rule, TimeZoneRuleQuery* query)
Description
Obtains the last effective time of the time zone rule based on TimeArrayTimeZoneRule.
System capability: SystemCapability.Global.I18n
Since: 22
Parameters
| Name | Description |
|---|---|
| AnnualTimeZoneRule* rule | Time zone rule AnnualTimeZoneRule that takes effect every year. |
| TimeZoneRuleQuery* query | Used to input the query information and receive the query result. |
Returns
| Type | Description |
|---|---|
| I18n_ErrorCode | 0: Success. 8900001: Invalid input parameters. 8900050: Unexpected error, for example, memory error. |
OH_i18n_GetNextStartFromTimeArrayTimeZoneRule()
I18n_ErrorCode OH_i18n_GetNextStartFromTimeArrayTimeZoneRule(TimeArrayTimeZoneRule* rule, TimeZoneRuleQuery* query)
Description
Obtains the next effective time of the time zone rule after the base time based on TimeArrayTimeZoneRule.
System capability: SystemCapability.Global.I18n
Since: 22
Parameters
| Name | Description |
|---|---|
| TimeArrayTimeZoneRule* rule | Time zone rule TimeArrayTimeZoneRule defined by the start timestamp array. |
| TimeZoneRuleQuery* query | Used to input the query information and receive the query result. |
Returns
| Type | Description |
|---|---|
| I18n_ErrorCode | 0: Success. 8900001: Invalid input parameters. 8900050: Unexpected error, for example, memory error. |
OH_i18n_GetNextStartFromAnnualTimeZoneRule()
I18n_ErrorCode OH_i18n_GetNextStartFromAnnualTimeZoneRule(AnnualTimeZoneRule* rule, TimeZoneRuleQuery* query)
Description
Obtains the next effective time of the time zone rule after the base time based on AnnualTimeZoneRule.
System capability: SystemCapability.Global.I18n
Since: 22
Parameters
| Name | Description |
|---|---|
| AnnualTimeZoneRule* rule | Time zone rule AnnualTimeZoneRule that takes effect every year. |
| TimeZoneRuleQuery* query | Used to input the query information and receive the query result. |
Returns
| Type | Description |
|---|---|
| I18n_ErrorCode | 0: Success. 8900001: Invalid input parameters. 8900050: Unexpected error, for example, memory error. |
OH_i18n_GetPrevStartFromTimeArrayTimeZoneRule()
I18n_ErrorCode OH_i18n_GetPrevStartFromTimeArrayTimeZoneRule(TimeArrayTimeZoneRule* rule, TimeZoneRuleQuery* query)
Description
Obtains the last effective time of the time zone rule before the base time based on TimeArrayTimeZoneRule.
System capability: SystemCapability.Global.I18n
Since: 22
Parameters
| Name | Description |
|---|---|
| TimeArrayTimeZoneRule* rule | Time zone rule TimeArrayTimeZoneRule defined by the start timestamp array. |
| TimeZoneRuleQuery* query | Used to input the query information and receive the query result. |
Returns
| Type | Description |
|---|---|
| I18n_ErrorCode | 0: Success. 8900001: Invalid input parameters. 8900050: Unexpected error, for example, memory error. |
OH_i18n_GetPrevStartFromAnnualTimeZoneRule()
I18n_ErrorCode OH_i18n_GetPrevStartFromAnnualTimeZoneRule(AnnualTimeZoneRule* rule, TimeZoneRuleQuery* query)
Description
Obtains the last effective time of the time zone rule before the base time based on AnnualTimeZoneRule.
System capability: SystemCapability.Global.I18n
Since: 22
Parameters
| Name | Description |
|---|---|
| AnnualTimeZoneRule* rule | Time zone rule AnnualTimeZoneRule that takes effect every year. |
| TimeZoneRuleQuery* query | Used to input the query information and receive the query result. |
Returns
| Type | Description |
|---|---|
| I18n_ErrorCode | 0: Success. 8900001: Invalid input parameters. 8900050: Unexpected error, for example, memory error. |
OH_i18n_GetStartTimeAt()
I18n_ErrorCode OH_i18n_GetStartTimeAt(TimeArrayTimeZoneRule* rule, int32_t index, double* result)
Description
Obtains the start time of the time zone rule at the specified index based on TimeArrayTimeZoneRule.
System capability: SystemCapability.Global.I18n
Since: 22
Parameters
| Name | Description |
|---|---|
| TimeArrayTimeZoneRule* rule | Time zone rule TimeArrayTimeZoneRule defined by the start timestamp array. |
| int32_t index | Index of the start time. |
| double* result | Start time of the rule. |
Returns
| Type | Description |
|---|---|
| I18n_ErrorCode | 0: Success. 8900001: Invalid input parameters. 8900050: Unexpected error, for example, memory error. |
OH_i18n_GetStartInYear()
I18n_ErrorCode OH_i18n_GetStartInYear(AnnualTimeZoneRule* rule, int32_t year, TimeZoneRuleQuery* query)
Description
Obtains the effective time of the time zone rule in a specified year based on AnnualTimeZoneRule.
System capability: SystemCapability.Global.I18n
Since: 22
Parameters
| Name | Description |
|---|---|
| AnnualTimeZoneRule* rule | Time zone rule AnnualTimeZoneRule that takes effect every year. |
| int32_t year | Year to be queried. |
| TimeZoneRuleQuery* query | Used to input the query information and receive the query result. |
Returns
| Type | Description |
|---|---|
| I18n_ErrorCode | 0: Success. 8900001: Invalid input parameters. 8900050: Unexpected error, for example, memory error. |