1# TimeService 2 3 4## 概述 5 6描述TimeService向应用提供时间时区能力。 7 8**起始版本:** 12 9 10 11## 汇总 12 13 14### 文件 15 16| 名称 | 描述 | 17| -------- | -------- | 18| [time_service.h](time__service_8h.md) | 声明获取时间时区信息的API。 | 19 20 21### 类型定义 22 23| 名称 | 描述 | 24| -------- | -------- | 25| typedef enum [TimeService_ErrCode](#timeservice_errcode)[TimeService_ErrCode](#timeservice_errcode) | 枚举错误码。 | 26 27 28### 枚举 29 30| 名称 | 描述 | 31| -------- | -------- | 32| [TimeService_ErrCode](#timeservice_errcode) {<br/>TIMESERVICE_ERR_OK = 0,<br/>TIMESERVICE_ERR_INTERNAL_ERROR = 13000001,<br/>TIMESERVICE_ERR_INVALID_PARAMETER = 13000002<br/>} | 枚举错误码。 | 33 34 35### 函数 36 37| 名称 | 描述 | 38| -------- | -------- | 39| [TimeService_ErrCode](#timeservice_errcode)[OH_TimeService_GetTimeZone](#oh_timeservice_gettimezone) (char \*timeZone, uint32_t len) | 获取当前系统时区。 | 40 41 42## 类型定义说明 43 44 45### TimeService_ErrCode 46 47``` 48typedef enum TimeService_ErrCode TimeService_ErrCode 49``` 50 51**描述** 52 53枚举错误码。 54 55**起始版本:** 12 56 57 58## 枚举类型说明 59 60 61### TimeService_ErrCode 62 63``` 64enum TimeService_ErrCode 65``` 66 67**描述** 68 69枚举错误码。 70 71**起始版本:** 12 72 73| 枚举值 | 描述 | 74| -------- | -------- | 75| TIMESERVICE_ERR_OK | 成功。 | 76| TIMESERVICE_ERR_INTERNAL_ERROR | 获取系统参数失败。 | 77| TIMESERVICE_ERR_INVALID_PARAMETER | 无效的参数。 | 78 79 80## 函数说明 81 82 83### OH_TimeService_GetTimeZone() 84 85``` 86TimeService_ErrCode OH_TimeService_GetTimeZone (char * timeZone, uint32_t len ) 87``` 88 89**描述** 90 91获取当前系统时区。 92 93**系统能力:** SystemCapability.MiscServices.Time 94 95**起始版本:** 12 96 97**参数:** 98 99| 名称 | 描述 | 100| -------- | -------- | 101| timeZone | 时区ID字符数组,成功时写入当前系统时区ID字符串,失败时写入空字符串,字符串以'\0'结尾。 | 102| len | 时区ID字符数组分配的内存大小,当前时区字符串没有最大长度规格,建议申请足够多的内存,至少不能低于31字节。 | 103 104**返回:** 105 106返回TIMESERVICE_ERR_OK表示成功; 107 108返回TIMESERVICE_ERR_INTERNAL_ERROR表示获取系统参数失败; 109 110返回TIMESERVICE_ERR_INVALID_PARAMETER表示timeZone为NULL指针或时区名称(不包括结束字符('\0'))的大小大于或等于len。 111