openharmony 鸿蒙 capi-timezone-h

2026-08-25 浏览 (1)

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

Nametypedef KeywordDescription
DateTimeRuleDateTimeRuleRule of time and date.
InitialTimeZoneRuleInitialTimeZoneRuleStart time zone rule.
TimeArrayTimeZoneRuleTimeArrayTimeZoneRuleTime zone rule defined by the start timestamp array.
AnnualTimeZoneRuleAnnualTimeZoneRuleTime zone rule that takes effect annually.
TimeZoneRulesTimeZoneRulesComplete time zone rule.
TimeZoneRuleQueryTimeZoneRuleQueryUsed to input the query information and receive the query result.

Enums

Nametypedef KeywordDescription
DateRuleTypeDateRuleTypeEnumerates the date rule types.
TimeRuleTypeTimeRuleTypeEnumerates the time rule types.

Macros

NameDescription
MAX_YEAR_IN_ANNUAL_TIMEZONE_RULE 0x7fffffffMax year of the time zone rule that takes effect annually.
Since: 22

Functions

NameDescription
I18n_ErrorCode OH_i18n_GetTimeZoneRules(const char* timeZoneID, TimeZoneRules* rules)Obtains the complete time zone rule based on the time zone ID.
I18n_ErrorCode OH_i18n_GetFirstStartFromTimeArrayTimeZoneRule(TimeArrayTimeZoneRule* rule, TimeZoneRuleQuery* query)Obtains the first effective time of the time zone rule based on TimeArrayTimeZoneRule.
I18n_ErrorCode OH_i18n_GetFirstStartFromAnnualTimeZoneRule(AnnualTimeZoneRule* rule, TimeZoneRuleQuery* query)Obtains the first effective time of the time zone rule based on AnnualTimeZoneRule.
I18n_ErrorCode OH_i18n_GetFinalStartFromTimeArrayTimeZoneRule(TimeArrayTimeZoneRule* rule, TimeZoneRuleQuery* query)Obtains the last effective time of the time zone rule based on TimeArrayTimeZoneRule.
I18n_ErrorCode OH_i18n_GetFinalStartFromAnnualTimeZoneRule(AnnualTimeZoneRule* rule, TimeZoneRuleQuery* query)Obtains the last effective time of the time zone rule based on TimeArrayTimeZoneRule.
I18n_ErrorCode OH_i18n_GetNextStartFromTimeArrayTimeZoneRule(TimeArrayTimeZoneRule* rule, TimeZoneRuleQuery* query)Obtains the next effective time of the time zone rule after the base time based on TimeArrayTimeZoneRule.
I18n_ErrorCode OH_i18n_GetNextStartFromAnnualTimeZoneRule(AnnualTimeZoneRule* rule, TimeZoneRuleQuery* query)Obtains the next effective time of the time zone rule after the base time based on AnnualTimeZoneRule.
I18n_ErrorCode OH_i18n_GetPrevStartFromTimeArrayTimeZoneRule(TimeArrayTimeZoneRule* rule, TimeZoneRuleQuery* query)Obtains the last effective time of the time zone rule before the base time based on TimeArrayTimeZoneRule.
I18n_ErrorCode OH_i18n_GetPrevStartFromAnnualTimeZoneRule(AnnualTimeZoneRule* rule, TimeZoneRuleQuery* query)Obtains the last effective time of the time zone rule before the base time based on AnnualTimeZoneRule.
I18n_ErrorCode OH_i18n_GetStartTimeAt(TimeArrayTimeZoneRule* rule, int32_t index, double* result)Obtains the start time of the time zone rule at the specified index based on TimeArrayTimeZoneRule.
I18n_ErrorCode OH_i18n_GetStartInYear(AnnualTimeZoneRule* rule, int32_t year, TimeZoneRuleQuery* query)Obtains the effective time of the time zone rule in a specified year based on AnnualTimeZoneRule.

Enum Description

DateRuleType

enum DateRuleType

Description

Enumerates the date rule types.

System capability: SystemCapability.Global.I18n

Since: 22

ValueDescription
DOM = 0Day of the month. For example, October 16 in 2025 is the 16th day of October.
DOW = 1Week day of the month. For example, October 16 in 2025 is the third Thursday of October.
DOW_GEQ_DOM = 2First 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 = 3Last 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

ValueDescription
WALL_TIME = 0Local clock time (not subject to time zone offset).
STANDARD_TIME = 1Local standard time (not subject to DST offset).
UTC_TIME = 2World 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

NameDescription
const char* timeZoneIDTime zone ID, for example, Asia/Shanghai.
TimeZoneRules* rulesObtains the complete time zone rule TimeZoneRules corresponding to the time zone ID.

Returns

TypeDescription
I18n_ErrorCode0: 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

NameDescription
TimeArrayTimeZoneRule* ruleTime zone rule TimeArrayTimeZoneRule defined by the start timestamp array.
TimeZoneRuleQuery* queryUsed to input the query information and receive the query result.

Returns

TypeDescription
I18n_ErrorCode0: 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

NameDescription
AnnualTimeZoneRule* ruleTime zone rule AnnualTimeZoneRule that takes effect every year.
TimeZoneRuleQuery* queryUsed to input the query information and receive the query result.

Returns

TypeDescription
I18n_ErrorCode0: 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

NameDescription
TimeArrayTimeZoneRule* ruleTime zone rule TimeArrayTimeZoneRule defined by the start timestamp array.
TimeZoneRuleQuery* queryUsed to input the query information and receive the query result.

Returns

TypeDescription
I18n_ErrorCode0: 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

NameDescription
AnnualTimeZoneRule* ruleTime zone rule AnnualTimeZoneRule that takes effect every year.
TimeZoneRuleQuery* queryUsed to input the query information and receive the query result.

Returns

TypeDescription
I18n_ErrorCode0: 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

NameDescription
TimeArrayTimeZoneRule* ruleTime zone rule TimeArrayTimeZoneRule defined by the start timestamp array.
TimeZoneRuleQuery* queryUsed to input the query information and receive the query result.

Returns

TypeDescription
I18n_ErrorCode0: 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

NameDescription
AnnualTimeZoneRule* ruleTime zone rule AnnualTimeZoneRule that takes effect every year.
TimeZoneRuleQuery* queryUsed to input the query information and receive the query result.

Returns

TypeDescription
I18n_ErrorCode0: 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

NameDescription
TimeArrayTimeZoneRule* ruleTime zone rule TimeArrayTimeZoneRule defined by the start timestamp array.
TimeZoneRuleQuery* queryUsed to input the query information and receive the query result.

Returns

TypeDescription
I18n_ErrorCode0: 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

NameDescription
AnnualTimeZoneRule* ruleTime zone rule AnnualTimeZoneRule that takes effect every year.
TimeZoneRuleQuery* queryUsed to input the query information and receive the query result.

Returns

TypeDescription
I18n_ErrorCode0: 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

NameDescription
TimeArrayTimeZoneRule* ruleTime zone rule TimeArrayTimeZoneRule defined by the start timestamp array.
int32_t indexIndex of the start time.
double* resultStart time of the rule.

Returns

TypeDescription
I18n_ErrorCode0: 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

NameDescription
AnnualTimeZoneRule* ruleTime zone rule AnnualTimeZoneRule that takes effect every year.
int32_t yearYear to be queried.
TimeZoneRuleQuery* queryUsed to input the query information and receive the query result.

Returns

TypeDescription
I18n_ErrorCode0: Success.
8900001: Invalid input parameters.
8900050: Unexpected error, for example, memory error.

你可能感兴趣的鸿蒙文章

openharmony 鸿蒙 capi-i18n-initialtimezonerule

openharmony 鸿蒙 capi-i18n-timezonerules

openharmony 鸿蒙 capi-resmgr-common-h

openharmony 鸿蒙 capi-i18n-annualtimezonerule

openharmony 鸿蒙 errorcode-font-manager

openharmony 鸿蒙 capi-raw-dir-h

openharmony 鸿蒙 capi-i18n-timezonerulequery

openharmony 鸿蒙 capi-errorcode-h

openharmony 鸿蒙 js-apis-resource-manager

openharmony 鸿蒙 js-apis-sendableResource

  • 所属分类: 后端技术
  • 本文标签: 鸿蒙 软件
  • 版权声明: 本文链接 https://seaxiang.com/blog/RWfEtnYd