1e41f4b71Sopenharmony_ci# @ohos.systemDateTime (System Time and Time Zone) (System API) 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ciThe **systemDateTime** module provides system time and time zone features. You can use the APIs of this module to set and obtain the system time and time zone. 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci> **NOTE** 6e41f4b71Sopenharmony_ci> 7e41f4b71Sopenharmony_ci> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. 8e41f4b71Sopenharmony_ci 9e41f4b71Sopenharmony_ci## Modules to Import 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_ci```ts 12e41f4b71Sopenharmony_ciimport { systemDateTime } from '@kit.BasicServicesKit'; 13e41f4b71Sopenharmony_ci``` 14e41f4b71Sopenharmony_ci 15e41f4b71Sopenharmony_ci## TimeType<sup>10+</sup> 16e41f4b71Sopenharmony_ci 17e41f4b71Sopenharmony_ciEnumerates the types of time to obtain. 18e41f4b71Sopenharmony_ci 19e41f4b71Sopenharmony_ci**System capability**: SystemCapability.MiscServices.Time 20e41f4b71Sopenharmony_ci 21e41f4b71Sopenharmony_ci| Name | Value | Description | 22e41f4b71Sopenharmony_ci| ------- | ---- | ------------------------------------------------ | 23e41f4b71Sopenharmony_ci| STARTUP | 0 | Number of milliseconds elapsed since system startup, including the deep sleep time. | 24e41f4b71Sopenharmony_ci| ACTIVE | 1 | Number of milliseconds elapsed since system startup, excluding the deep sleep time.| 25e41f4b71Sopenharmony_ci 26e41f4b71Sopenharmony_ci## systemDateTime.setTime 27e41f4b71Sopenharmony_ci 28e41f4b71Sopenharmony_cisetTime(time : number, callback : AsyncCallback<void>) : void 29e41f4b71Sopenharmony_ci 30e41f4b71Sopenharmony_ciSets the system time. This API uses an asynchronous callback to return the result. 31e41f4b71Sopenharmony_ci 32e41f4b71Sopenharmony_ci**System API**: This is a system API. 33e41f4b71Sopenharmony_ci 34e41f4b71Sopenharmony_ci**System capability**: SystemCapability.MiscServices.Time 35e41f4b71Sopenharmony_ci 36e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.SET_TIME 37e41f4b71Sopenharmony_ci 38e41f4b71Sopenharmony_ci**Parameters** 39e41f4b71Sopenharmony_ci 40e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 41e41f4b71Sopenharmony_ci| -------- | ----------- | ---- | ---------------- | 42e41f4b71Sopenharmony_ci| time | number | Yes | Timestamp to set, in milliseconds. | 43e41f4b71Sopenharmony_ci| callback | AsyncCallback<void> | Yes | Callback used to return the result.| 44e41f4b71Sopenharmony_ci 45e41f4b71Sopenharmony_ci**Error codes** 46e41f4b71Sopenharmony_ci 47e41f4b71Sopenharmony_ciFor details about the error codes, see [Time and Time Zone Service Error Codes](./errorcode-time.md). 48e41f4b71Sopenharmony_ci 49e41f4b71Sopenharmony_ci| ID| Error Message | 50e41f4b71Sopenharmony_ci| -------- |-------------------------------------------------------------------------------------------------------------| 51e41f4b71Sopenharmony_ci| 201 | Permission denied. | 52e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 53e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 54e41f4b71Sopenharmony_ci 55e41f4b71Sopenharmony_ci**Example** 56e41f4b71Sopenharmony_ci 57e41f4b71Sopenharmony_ci```ts 58e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 59e41f4b71Sopenharmony_ci 60e41f4b71Sopenharmony_ci// Set the system time to 2021-01-20 02:36:25. 61e41f4b71Sopenharmony_cilet time = 1611081385000; 62e41f4b71Sopenharmony_citry { 63e41f4b71Sopenharmony_ci systemDateTime.setTime(time, (error: BusinessError) => { 64e41f4b71Sopenharmony_ci if (error) { 65e41f4b71Sopenharmony_ci console.info(`Failed to set time. message: ${error.message}, code: ${error.code}`); 66e41f4b71Sopenharmony_ci return; 67e41f4b71Sopenharmony_ci } 68e41f4b71Sopenharmony_ci console.info(`Succeeded in setting time`); 69e41f4b71Sopenharmony_ci }); 70e41f4b71Sopenharmony_ci} catch(e) { 71e41f4b71Sopenharmony_ci let error = e as BusinessError; 72e41f4b71Sopenharmony_ci console.info(`Failed to set time. message: ${error.message}, code: ${error.code}`); 73e41f4b71Sopenharmony_ci} 74e41f4b71Sopenharmony_ci``` 75e41f4b71Sopenharmony_ci 76e41f4b71Sopenharmony_ci## systemDateTime.setTime 77e41f4b71Sopenharmony_ci 78e41f4b71Sopenharmony_cisetTime(time : number) : Promise<void> 79e41f4b71Sopenharmony_ci 80e41f4b71Sopenharmony_ciSets the system time. This API uses a promise to return the result. 81e41f4b71Sopenharmony_ci 82e41f4b71Sopenharmony_ci**System API**: This is a system API. 83e41f4b71Sopenharmony_ci 84e41f4b71Sopenharmony_ci**System capability**: SystemCapability.MiscServices.Time 85e41f4b71Sopenharmony_ci 86e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.SET_TIME 87e41f4b71Sopenharmony_ci 88e41f4b71Sopenharmony_ci**Parameters** 89e41f4b71Sopenharmony_ci 90e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 91e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------------------ | 92e41f4b71Sopenharmony_ci| time | number | Yes | Timestamp to set, in milliseconds.| 93e41f4b71Sopenharmony_ci 94e41f4b71Sopenharmony_ci**Return value** 95e41f4b71Sopenharmony_ci 96e41f4b71Sopenharmony_ci| Type | Description | 97e41f4b71Sopenharmony_ci| ------------------- | ------------------------- | 98e41f4b71Sopenharmony_ci| Promise<void> | Promise that returns no value.| 99e41f4b71Sopenharmony_ci 100e41f4b71Sopenharmony_ci**Error codes** 101e41f4b71Sopenharmony_ci 102e41f4b71Sopenharmony_ciFor details about the error codes, see [Time and Time Zone Service Error Codes](./errorcode-time.md). 103e41f4b71Sopenharmony_ci 104e41f4b71Sopenharmony_ci| ID| Error Message | 105e41f4b71Sopenharmony_ci| -------- |-------------------------------------------------------------------------------------------------------------| 106e41f4b71Sopenharmony_ci| 201 | Permission denied. | 107e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 108e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 109e41f4b71Sopenharmony_ci 110e41f4b71Sopenharmony_ci**Example** 111e41f4b71Sopenharmony_ci 112e41f4b71Sopenharmony_ci```ts 113e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 114e41f4b71Sopenharmony_ci 115e41f4b71Sopenharmony_ci// Set the system time to 2021-01-20 02:36:25. 116e41f4b71Sopenharmony_cilet time = 1611081385000; 117e41f4b71Sopenharmony_citry { 118e41f4b71Sopenharmony_ci systemDateTime.setTime(time).then(() => { 119e41f4b71Sopenharmony_ci console.info(`Succeeded in setting time.`); 120e41f4b71Sopenharmony_ci }).catch((error: BusinessError) => { 121e41f4b71Sopenharmony_ci console.info(`Failed to set time. message: ${error.message}, code: ${error.code}`); 122e41f4b71Sopenharmony_ci }); 123e41f4b71Sopenharmony_ci} catch(e) { 124e41f4b71Sopenharmony_ci let error = e as BusinessError; 125e41f4b71Sopenharmony_ci console.info(`Failed to set time. message: ${error.message}, code: ${error.code}`); 126e41f4b71Sopenharmony_ci} 127e41f4b71Sopenharmony_ci``` 128e41f4b71Sopenharmony_ci 129e41f4b71Sopenharmony_ci## systemDateTime.setDate<sup>(deprecated)</sup> 130e41f4b71Sopenharmony_ci 131e41f4b71Sopenharmony_cisetDate(date: Date, callback: AsyncCallback<void>): void 132e41f4b71Sopenharmony_ci 133e41f4b71Sopenharmony_ciSets the system date. This API uses an asynchronous callback to return the result. 134e41f4b71Sopenharmony_ci 135e41f4b71Sopenharmony_ci> **NOTE** 136e41f4b71Sopenharmony_ci> 137e41f4b71Sopenharmony_ci> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [systemDateTime.setTime](#systemdatetimesettime) instead. 138e41f4b71Sopenharmony_ci 139e41f4b71Sopenharmony_ci**System API**: This is a system API. 140e41f4b71Sopenharmony_ci 141e41f4b71Sopenharmony_ci**System capability**: SystemCapability.MiscServices.Time 142e41f4b71Sopenharmony_ci 143e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.SET_TIME 144e41f4b71Sopenharmony_ci 145e41f4b71Sopenharmony_ci**Parameters** 146e41f4b71Sopenharmony_ci 147e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 148e41f4b71Sopenharmony_ci| -------- | ------------- | ---- |-------------| 149e41f4b71Sopenharmony_ci| date | Date | Yes | Target date. The value must be greater than 0.| 150e41f4b71Sopenharmony_ci| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 151e41f4b71Sopenharmony_ci 152e41f4b71Sopenharmony_ci**Error codes** 153e41f4b71Sopenharmony_ci 154e41f4b71Sopenharmony_ciFor details about the error codes, see [Time and Time Zone Service Error Codes](./errorcode-time.md). 155e41f4b71Sopenharmony_ci 156e41f4b71Sopenharmony_ci| ID| Error Message | 157e41f4b71Sopenharmony_ci| -------- |----------------------------------------------------------------------------------------------------------------------------------------------| 158e41f4b71Sopenharmony_ci| 201 | Permission denied. | 159e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 160e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed. | 161e41f4b71Sopenharmony_ci 162e41f4b71Sopenharmony_ci**Example** 163e41f4b71Sopenharmony_ci 164e41f4b71Sopenharmony_ci```ts 165e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 166e41f4b71Sopenharmony_ci 167e41f4b71Sopenharmony_cilet date = new Date(); 168e41f4b71Sopenharmony_citry { 169e41f4b71Sopenharmony_ci systemDateTime.setDate(date, (error: BusinessError) => { 170e41f4b71Sopenharmony_ci if (error) { 171e41f4b71Sopenharmony_ci console.info(`Failed to set date. message: ${error.message}, code: ${error.code}`); 172e41f4b71Sopenharmony_ci return; 173e41f4b71Sopenharmony_ci } 174e41f4b71Sopenharmony_ci console.info(`Succeeded in setting date.`); 175e41f4b71Sopenharmony_ci }); 176e41f4b71Sopenharmony_ci} catch(e) { 177e41f4b71Sopenharmony_ci let error = e as BusinessError; 178e41f4b71Sopenharmony_ci console.info(`Failed to set date. message: ${error.message}, code: ${error.code}`); 179e41f4b71Sopenharmony_ci} 180e41f4b71Sopenharmony_ci``` 181e41f4b71Sopenharmony_ci 182e41f4b71Sopenharmony_ci## systemDateTime.setDate<sup>(deprecated)</sup> 183e41f4b71Sopenharmony_ci 184e41f4b71Sopenharmony_cisetDate(date: Date): Promise<void> 185e41f4b71Sopenharmony_ci 186e41f4b71Sopenharmony_ciSets the system date. This API uses a promise to return the result. 187e41f4b71Sopenharmony_ci 188e41f4b71Sopenharmony_ci> **NOTE** 189e41f4b71Sopenharmony_ci> 190e41f4b71Sopenharmony_ci> This API is supported since API version 9 and deprecated since API version 10. You are advised to use [systemDateTime.setTime](#systemdatetimesettime) instead. 191e41f4b71Sopenharmony_ci 192e41f4b71Sopenharmony_ci**System API**: This is a system API. 193e41f4b71Sopenharmony_ci 194e41f4b71Sopenharmony_ci**System capability**: SystemCapability.MiscServices.Time 195e41f4b71Sopenharmony_ci 196e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.SET_TIME 197e41f4b71Sopenharmony_ci 198e41f4b71Sopenharmony_ci**Parameters** 199e41f4b71Sopenharmony_ci 200e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description | 201e41f4b71Sopenharmony_ci| ------ | ---- | ---- | ---------- | 202e41f4b71Sopenharmony_ci| date | Date | Yes | Target date, which is mandatory.| 203e41f4b71Sopenharmony_ci 204e41f4b71Sopenharmony_ci**Return value** 205e41f4b71Sopenharmony_ci 206e41f4b71Sopenharmony_ci| Type | Description | 207e41f4b71Sopenharmony_ci| ------------------- | -------------------- | 208e41f4b71Sopenharmony_ci| Promise<void> | Promise that returns no value.| 209e41f4b71Sopenharmony_ci 210e41f4b71Sopenharmony_ci**Error codes** 211e41f4b71Sopenharmony_ci 212e41f4b71Sopenharmony_ciFor details about the error codes, see [Time and Time Zone Service Error Codes](./errorcode-time.md). 213e41f4b71Sopenharmony_ci 214e41f4b71Sopenharmony_ci| ID| Error Message | 215e41f4b71Sopenharmony_ci| -------- |----------------------------------------------------------------------------------------------------------------------------------------------| 216e41f4b71Sopenharmony_ci| 201 | Permission denied. | 217e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 218e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed. | 219e41f4b71Sopenharmony_ci 220e41f4b71Sopenharmony_ci**Example** 221e41f4b71Sopenharmony_ci 222e41f4b71Sopenharmony_ci```ts 223e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 224e41f4b71Sopenharmony_ci 225e41f4b71Sopenharmony_cilet date = new Date(); 226e41f4b71Sopenharmony_citry { 227e41f4b71Sopenharmony_ci systemDateTime.setDate(date).then(() => { 228e41f4b71Sopenharmony_ci console.info(`Succeeded in setting date.`); 229e41f4b71Sopenharmony_ci }).catch((error: BusinessError) => { 230e41f4b71Sopenharmony_ci console.info(`Failed to set date. message: ${error.message}, code: ${error.code}`); 231e41f4b71Sopenharmony_ci }); 232e41f4b71Sopenharmony_ci} catch(e) { 233e41f4b71Sopenharmony_ci let error = e as BusinessError; 234e41f4b71Sopenharmony_ci console.info(`Failed to set date. message: ${error.message}, code: ${error.code}`); 235e41f4b71Sopenharmony_ci} 236e41f4b71Sopenharmony_ci``` 237e41f4b71Sopenharmony_ci 238e41f4b71Sopenharmony_ci## systemDateTime.setTimezone 239e41f4b71Sopenharmony_ci 240e41f4b71Sopenharmony_cisetTimezone(timezone: string, callback: AsyncCallback<void>): void 241e41f4b71Sopenharmony_ci 242e41f4b71Sopenharmony_ciSets the system time zone. This API uses an asynchronous callback to return the result. 243e41f4b71Sopenharmony_ci 244e41f4b71Sopenharmony_ci**System API**: This is a system API. 245e41f4b71Sopenharmony_ci 246e41f4b71Sopenharmony_ci**System capability**: SystemCapability.MiscServices.Time 247e41f4b71Sopenharmony_ci 248e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.SET_TIME_ZONE 249e41f4b71Sopenharmony_ci 250e41f4b71Sopenharmony_ci**Parameters** 251e41f4b71Sopenharmony_ci 252e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 253e41f4b71Sopenharmony_ci| -------- | ------------- | ---- | -------------------------- | 254e41f4b71Sopenharmony_ci| timezone | string | Yes | System time zone to set. For details, see [Supported System Time Zones](#supported-system-time-zones). | 255e41f4b71Sopenharmony_ci| callback | AsyncCallback<void> | Yes | Callback used to return the result.| 256e41f4b71Sopenharmony_ci 257e41f4b71Sopenharmony_ci**Error codes** 258e41f4b71Sopenharmony_ci 259e41f4b71Sopenharmony_ciFor details about the error codes, see [Time and Time Zone Service Error Codes](./errorcode-time.md). 260e41f4b71Sopenharmony_ci 261e41f4b71Sopenharmony_ci| ID| Error Message | 262e41f4b71Sopenharmony_ci| -------- |-------------------------------------------------------------------------------------------------------------| 263e41f4b71Sopenharmony_ci| 201 | Permission denied. | 264e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 265e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 266e41f4b71Sopenharmony_ci 267e41f4b71Sopenharmony_ci**Example** 268e41f4b71Sopenharmony_ci 269e41f4b71Sopenharmony_ci```ts 270e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 271e41f4b71Sopenharmony_ci 272e41f4b71Sopenharmony_citry { 273e41f4b71Sopenharmony_ci systemDateTime.setTimezone('Asia/Shanghai', (error: BusinessError) => { 274e41f4b71Sopenharmony_ci if (error) { 275e41f4b71Sopenharmony_ci console.info(`Failed to set timezone. message: ${error.message}, code: ${error.code}`); 276e41f4b71Sopenharmony_ci return; 277e41f4b71Sopenharmony_ci } 278e41f4b71Sopenharmony_ci console.info(`Succeeded in setting timezone.`); 279e41f4b71Sopenharmony_ci }); 280e41f4b71Sopenharmony_ci} catch(e) { 281e41f4b71Sopenharmony_ci let error = e as BusinessError; 282e41f4b71Sopenharmony_ci console.info(`Failed to set timezone. message: ${error.message}, code: ${error.code}`); 283e41f4b71Sopenharmony_ci} 284e41f4b71Sopenharmony_ci``` 285e41f4b71Sopenharmony_ci 286e41f4b71Sopenharmony_ci## systemDateTime.setTimezone 287e41f4b71Sopenharmony_ci 288e41f4b71Sopenharmony_cisetTimezone(timezone: string): Promise<void> 289e41f4b71Sopenharmony_ci 290e41f4b71Sopenharmony_ciSets the system time zone. This API uses a promise to return the result. 291e41f4b71Sopenharmony_ci 292e41f4b71Sopenharmony_ci**System API**: This is a system API. 293e41f4b71Sopenharmony_ci 294e41f4b71Sopenharmony_ci**System capability**: SystemCapability.MiscServices.Time 295e41f4b71Sopenharmony_ci 296e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.SET_TIME_ZONE 297e41f4b71Sopenharmony_ci 298e41f4b71Sopenharmony_ci**Parameters** 299e41f4b71Sopenharmony_ci 300e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 301e41f4b71Sopenharmony_ci| -------- | ------ | ---- | ---------- | 302e41f4b71Sopenharmony_ci| timezone | string | Yes | System time zone to set. For details, see [Supported System Time Zones](#supported-system-time-zones).| 303e41f4b71Sopenharmony_ci 304e41f4b71Sopenharmony_ci**Return value** 305e41f4b71Sopenharmony_ci 306e41f4b71Sopenharmony_ci| Type | Description | 307e41f4b71Sopenharmony_ci| ------------------- | -------------------- | 308e41f4b71Sopenharmony_ci| Promise<void> | Promise that returns no value.| 309e41f4b71Sopenharmony_ci 310e41f4b71Sopenharmony_ci**Error codes** 311e41f4b71Sopenharmony_ci 312e41f4b71Sopenharmony_ciFor details about the error codes, see [Time and Time Zone Service Error Codes](./errorcode-time.md). 313e41f4b71Sopenharmony_ci 314e41f4b71Sopenharmony_ci| ID| Error Message | 315e41f4b71Sopenharmony_ci| -------- |-------------------------------------------------------------------------------------------------------------| 316e41f4b71Sopenharmony_ci| 201 | Permission denied. | 317e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 318e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 319e41f4b71Sopenharmony_ci 320e41f4b71Sopenharmony_ci**Example** 321e41f4b71Sopenharmony_ci 322e41f4b71Sopenharmony_ci```ts 323e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 324e41f4b71Sopenharmony_ci 325e41f4b71Sopenharmony_citry { 326e41f4b71Sopenharmony_ci systemDateTime.setTimezone('Asia/Shanghai').then(() => { 327e41f4b71Sopenharmony_ci console.info(`Succeeded in setting timezone.`); 328e41f4b71Sopenharmony_ci }).catch((error: BusinessError) => { 329e41f4b71Sopenharmony_ci console.info(`Failed to set timezone. message: ${error.message}, code: ${error.code}`); 330e41f4b71Sopenharmony_ci }); 331e41f4b71Sopenharmony_ci} catch(e) { 332e41f4b71Sopenharmony_ci let error = e as BusinessError; 333e41f4b71Sopenharmony_ci console.info(`Failed to set timezone. message: ${error.message}, code: ${error.code}`); 334e41f4b71Sopenharmony_ci} 335e41f4b71Sopenharmony_ci``` 336e41f4b71Sopenharmony_ci 337e41f4b71Sopenharmony_ci## systemDateTime.updateNtpTime<sup>13+</sup> 338e41f4b71Sopenharmony_ci 339e41f4b71Sopenharmony_ciupdateNtpTime(): Promise<void> 340e41f4b71Sopenharmony_ci 341e41f4b71Sopenharmony_ciUpdates the NTP time from the NTP server This API returns the result asynchronously. In this way, the NTP time is updated from the NTP server only once within one hour. 342e41f4b71Sopenharmony_ci 343e41f4b71Sopenharmony_ci**System API**: This is a system API. 344e41f4b71Sopenharmony_ci 345e41f4b71Sopenharmony_ci**System capability**: SystemCapability.MiscServices.Time 346e41f4b71Sopenharmony_ci 347e41f4b71Sopenharmony_ci**Return value** 348e41f4b71Sopenharmony_ci 349e41f4b71Sopenharmony_ci| Type | Description | 350e41f4b71Sopenharmony_ci| ------------------- | -------------------- | 351e41f4b71Sopenharmony_ci| Promise<void> | Promise that returns no value.| 352e41f4b71Sopenharmony_ci 353e41f4b71Sopenharmony_ci**Error codes** 354e41f4b71Sopenharmony_ci 355e41f4b71Sopenharmony_ciFor details about the error codes, see [Time and Time Zone Service Error Codes](./errorcode-time.md). 356e41f4b71Sopenharmony_ci 357e41f4b71Sopenharmony_ci| ID| Error Message | 358e41f4b71Sopenharmony_ci|-------|-------------------------------------------------------------------------------------------------------------| 359e41f4b71Sopenharmony_ci| 13000001 | Network connection error or OS error. | 360e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 361e41f4b71Sopenharmony_ci 362e41f4b71Sopenharmony_ci**Example** 363e41f4b71Sopenharmony_ci 364e41f4b71Sopenharmony_ci```ts 365e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 366e41f4b71Sopenharmony_ci 367e41f4b71Sopenharmony_citry { 368e41f4b71Sopenharmony_ci systemDateTime.updateNtpTime().then(() => { 369e41f4b71Sopenharmony_ci console.info(`Succeeded in update ntp time.`); 370e41f4b71Sopenharmony_ci }).catch((error: BusinessError) => { 371e41f4b71Sopenharmony_ci console.error(`Failed to update ntp time. message: ${error.message}, code: ${error.code}`); 372e41f4b71Sopenharmony_ci }); 373e41f4b71Sopenharmony_ci} catch(e) { 374e41f4b71Sopenharmony_ci let error = e as BusinessError; 375e41f4b71Sopenharmony_ci console.error(`Failed to update ntp time. message: ${error.message}, code: ${error.code}`); 376e41f4b71Sopenharmony_ci} 377e41f4b71Sopenharmony_ci``` 378e41f4b71Sopenharmony_ci 379e41f4b71Sopenharmony_ci## systemDateTime.getNtpTime<sup>13+</sup> 380e41f4b71Sopenharmony_ci 381e41f4b71Sopenharmony_cigetNtpTime(): number 382e41f4b71Sopenharmony_ci 383e41f4b71Sopenharmony_ciObtains the actual time calculated based on the last updated NTP time. This API returns the result synchronously. 384e41f4b71Sopenharmony_ci 385e41f4b71Sopenharmony_ci**System API**: This is a system API. 386e41f4b71Sopenharmony_ci 387e41f4b71Sopenharmony_ci**System capability**: SystemCapability.MiscServices.Time 388e41f4b71Sopenharmony_ci 389e41f4b71Sopenharmony_ci**Return value** 390e41f4b71Sopenharmony_ci 391e41f4b71Sopenharmony_ci| Type | Description | 392e41f4b71Sopenharmony_ci| ------ |--------------------------------| 393e41f4b71Sopenharmony_ci| number | Unix epoch time (ms) calculated based on the last updated NTP time.| 394e41f4b71Sopenharmony_ci 395e41f4b71Sopenharmony_ci**Error codes** 396e41f4b71Sopenharmony_ci 397e41f4b71Sopenharmony_ciFor details about the error codes, see [Time and Time Zone Service Error Codes](./errorcode-time.md). 398e41f4b71Sopenharmony_ci 399e41f4b71Sopenharmony_ci| ID| Error Message | 400e41f4b71Sopenharmony_ci|-------|-------------------------------------------------------------------------------------------------------------| 401e41f4b71Sopenharmony_ci| 13000002 | updateNtpTime() is not called successfully. | 402e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 403e41f4b71Sopenharmony_ci 404e41f4b71Sopenharmony_ci**Example** 405e41f4b71Sopenharmony_ci 406e41f4b71Sopenharmony_ci```ts 407e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 408e41f4b71Sopenharmony_ci 409e41f4b71Sopenharmony_citry { 410e41f4b71Sopenharmony_ci let time = systemDateTime.getNtpTime(); 411e41f4b71Sopenharmony_ci} catch(e) { 412e41f4b71Sopenharmony_ci let error = e as BusinessError; 413e41f4b71Sopenharmony_ci console.error(`Failed to get ntp time. message: ${error.message}, code: ${error.code}`); 414e41f4b71Sopenharmony_ci} 415e41f4b71Sopenharmony_ci``` 416e41f4b71Sopenharmony_ci 417e41f4b71Sopenharmony_ci## Supported System Time Zones 418e41f4b71Sopenharmony_ci 419e41f4b71Sopenharmony_ciFor details about the supported system time zones, see API [I18n.SystemLocaleManager.getTimeZoneCityItemArray()](../apis-localization-kit/js-apis-i18n-sys.md#gettimezonecityitemarray10). 420