1# @ohos.enterprise.dateTimeManager (System Time Management) (System API) 2 3The **dateTimeManager** module provides APIs for system time management. 4 5> **NOTE** 6> 7> 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. 8> 9> The APIs of this module can be used only in the stage model. 10> 11> The APIs of this module can be called only by a [device administrator application](../../mdm/mdm-kit-guide.md#introduction) that is [enabled](js-apis-enterprise-adminManager-sys.md#adminmanagerenableadmin). 12> 13> The APIs provided by this module are system APIs. 14 15## Modules to Import 16 17```ts 18import { dateTimeManager } from '@kit.MDMKit'; 19``` 20 21## dateTimeManager.setDateTime 22 23setDateTime(admin: Want, time: number, callback: AsyncCallback\<void>): void 24 25Sets the system time through the specified device administrator application. This API uses an asynchronous callback to return the result. 26 27**Required permissions**: ohos.permission.ENTERPRISE_SET_DATETIME 28 29**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 30 31 32**Parameters** 33 34| Name | Type | Mandatory | Description | 35| ----- | ----------------------------------- | ---- | ------- | 36| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Device administrator application.| 37| time | number | Yes| Timestamp to set, in ms.| 38| callback | AsyncCallback\<void> | Yes| Callback used to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| 39 40**Error codes** 41 42For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 43 44| ID| Error Message | 45| ------- | ---------------------------------------------------------------------------- | 46| 9200001 | The application is not an administrator application of the device. | 47| 9200002 | The administrator application does not have permission to manage the device. | 48| 201 | Permission verification failed. The application does not have the permission required to call the API. | 49| 202 | Permission verification failed. A non-system application calls a system API. | 50| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 51 52**Example** 53 54```ts 55import { Want } from '@kit.AbilityKit'; 56let wantTemp: Want = { 57 bundleName: 'bundleName', 58 abilityName: 'abilityName', 59}; 60 61dateTimeManager.setDateTime(wantTemp, 1526003846000, (err) => { 62 if (err) { 63 console.error(`Failed to set date time. Code is ${err.code}, message is ${err.message}`); 64 return; 65 } 66 console.info('Succeeded in setting date time'); 67}) 68``` 69 70## dateTimeManager.setDateTime 71 72setDateTime(admin: Want, time: number): Promise\<void> 73 74Sets the system time through the specified device administrator application. This API uses a promise to return the result. 75 76**Required permissions**: ohos.permission.ENTERPRISE_SET_DATETIME 77 78**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 79 80 81**Parameters** 82 83| Name | Type | Mandatory | Description | 84| ----- | ----------------------------------- | ---- | ------- | 85| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Device administrator application.| 86| time | number | Yes| Timestamp to set, in ms.| 87 88**Return value** 89 90| Type | Description | 91| ----- | ----------------------------------- | 92| Promise\<void> | Promise that returns no value.| 93 94**Error codes** 95 96For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 97 98| ID| Error Message | 99| ------- | ---------------------------------------------------------------------------- | 100| 9200001 | The application is not an administrator application of the device. | 101| 9200002 | The administrator application does not have permission to manage the device. | 102| 201 | Permission verification failed. The application does not have the permission required to call the API. | 103| 202 | Permission verification failed. A non-system application calls a system API. | 104| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 105 106**Example** 107 108```ts 109import { Want } from '@kit.AbilityKit'; 110import { BusinessError } from '@kit.BasicServicesKit'; 111let wantTemp: Want = { 112 bundleName: 'bundleName', 113 abilityName: 'abilityName', 114}; 115 116dateTimeManager.setDateTime(wantTemp, 1526003846000).then(() => { 117 console.info('Succeeded in setting date time'); 118}).catch((err: BusinessError) => { 119 console.error(`Failed to set date time. Code is ${err.code}, message is ${err.message}`); 120}) 121``` 122 123## dateTimeManager.disallowModifyDateTime<sup>10+</sup> 124 125disallowModifyDateTime(admin: Want, disallow: boolean, callback: AsyncCallback\<void>): void 126 127Forbids the specified device administrator application to modify the system time. This API uses an asynchronous callback to return the result. 128 129**Required permissions**: ohos.permission.ENTERPRISE_SET_DATETIME 130 131**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 132 133 134**Parameters** 135 136| Name | Type | Mandatory | Description | 137| ----- | ----------------------------------- | ---- | ------- | 138| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Device administrator application.| 139| disallow | boolean | Yes| Whether to disallow modification of the system time. The value **true** means to disallow modification of the system time, and **false** means the opposite.| 140| callback | AsyncCallback\<void> | Yes| Callback used to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| 141 142**Error codes** 143 144For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 145 146| ID| Error Message | 147| ------- | ---------------------------------------------------------------------------- | 148| 9200001 | The application is not an administrator application of the device. | 149| 9200002 | The administrator application does not have permission to manage the device. | 150| 201 | Permission verification failed. The application does not have the permission required to call the API. | 151| 202 | Permission verification failed. A non-system application calls a system API. | 152| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 153 154**Example** 155 156```ts 157import { Want } from '@kit.AbilityKit'; 158let wantTemp: Want = { 159 bundleName: 'bundleName', 160 abilityName: 'abilityName', 161}; 162 163dateTimeManager.disallowModifyDateTime(wantTemp, true, (err) => { 164 if (err) { 165 console.error(`Failed to disallow modify date time. Code is ${err.code}, message is ${err.message}`); 166 return; 167 } 168 console.info('Succeeded in disallowing modify date time'); 169}) 170``` 171 172## dateTimeManager.disallowModifyDateTime<sup>10+</sup> 173 174disallowModifyDateTime(admin: Want, disallow: boolean): Promise\<void> 175 176Forbids the specified device administrator application to modify the system time. This API uses a promise to return the result. 177 178**Required permissions**: ohos.permission.ENTERPRISE_SET_DATETIME 179 180**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 181 182 183**Parameters** 184 185| Name | Type | Mandatory | Description | 186| ----- | ----------------------------------- | ---- | ------- | 187| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Device administrator application.| 188| disallow | boolean | Yes| Whether to disallow modification of the system time. The value **true** means to disallow modification of the system time, and **false** means the opposite.| 189 190**Return value** 191 192| Type | Description | 193| ----- | ----------------------------------- | 194| Promise\<void> | Promise that returns no value. If the operation fails, an error object will be thrown.| 195 196**Error codes** 197 198For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 199 200| ID| Error Message | 201| ------- | ---------------------------------------------------------------------------- | 202| 9200001 | The application is not an administrator application of the device. | 203| 9200002 | The administrator application does not have permission to manage the device. | 204| 201 | Permission verification failed. The application does not have the permission required to call the API. | 205| 202 | Permission verification failed. A non-system application calls a system API. | 206| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 207 208**Example** 209 210```ts 211import { Want } from '@kit.AbilityKit'; 212import { BusinessError } from '@kit.BasicServicesKit'; 213let wantTemp: Want = { 214 bundleName: 'bundleName', 215 abilityName: 'abilityName', 216}; 217 218dateTimeManager.disallowModifyDateTime(wantTemp, true).then(() => { 219 console.info('Succeeded in disallowing modify date time'); 220}).catch((err: BusinessError) => { 221 console.error(`Failed to disallow modify date time. Code is ${err.code}, message is ${err.message}`); 222}) 223``` 224 225## dateTimeManager.isModifyDateTimeDisallowed<sup>10+</sup> 226 227isModifyDateTimeDisallowed(admin: Want, callback: AsyncCallback\<boolean>): void 228 229Checks whether the system time modification is disallowed through the specified device administrator application. This API uses an asynchronous callback to return the result. 230 231**Required permissions**: ohos.permission.ENTERPRISE_SET_DATETIME 232 233**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 234 235 236**Parameters** 237 238| Name | Type | Mandatory | Description | 239| ----- | ----------------------------------- | ---- | ------- | 240| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Device administrator application.| 241| callback | AsyncCallback\<boolean> | Yes| Callback used to return the result. The value **true** means the system time modification is disallowed, and **false** means the opposite.| 242 243**Error codes** 244 245For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 246 247| ID| Error Message | 248| ------- | ---------------------------------------------------------------------------- | 249| 9200001 | The application is not an administrator application of the device. | 250| 9200002 | The administrator application does not have permission to manage the device. | 251| 201 | Permission verification failed. The application does not have the permission required to call the API. | 252| 202 | Permission verification failed. A non-system application calls a system API. | 253| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 254 255**Example** 256 257```ts 258import { Want } from '@kit.AbilityKit'; 259let wantTemp: Want = { 260 bundleName: 'bundleName', 261 abilityName: 'abilityName', 262}; 263 264dateTimeManager.isModifyDateTimeDisallowed(wantTemp, (err, result) => { 265 if (err) { 266 console.error(`Failed to query modify date time is disallowed or not. Code is ${err.code}, message is ${err.message}`); 267 return; 268 } 269 console.info(`Succeeded in querying modify date time is disallowed : ${result}`); 270}) 271``` 272 273## dateTimeManager.isModifyDateTimeDisallowed<sup>10+</sup> 274 275isModifyDateTimeDisallowed(admin: Want): Promise\<boolean> 276 277Checks whether the system time modification is disallowed through the specified device administrator application. This API uses a promise to return the result. 278 279**Required permissions**: ohos.permission.ENTERPRISE_SET_DATETIME 280 281**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 282 283 284**Parameters** 285 286| Name | Type | Mandatory | Description | 287| ----- | ----------------------------------- | ---- | ------- | 288| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Device administrator application.| 289 290**Return value** 291 292| Type | Description | 293| ----- | ----------------------------------- | 294| Promise\<boolean> | Promise used to return the result. The value **true** means the system time modification is disallowed, and **false** means the opposite.| 295 296**Error codes** 297 298For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 299 300| ID| Error Message | 301| ------- | ---------------------------------------------------------------------------- | 302| 9200001 | The application is not an administrator application of the device. | 303| 9200002 | The administrator application does not have permission to manage the device. | 304| 201 | Permission verification failed. The application does not have the permission required to call the API. | 305| 202 | Permission verification failed. A non-system application calls a system API. | 306| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 307 308**Example** 309 310```ts 311import { Want } from '@kit.AbilityKit'; 312import { BusinessError } from '@kit.BasicServicesKit'; 313let wantTemp: Want = { 314 bundleName: 'bundleName', 315 abilityName: 'abilityName', 316}; 317 318dateTimeManager.isModifyDateTimeDisallowed(wantTemp).then((result) => { 319 console.info(`Succeeded in querying modify date time is disallowed : ${result}`); 320}).catch((err: BusinessError) => { 321 console.error(`Failed to query modify date time is disallowed or not. Code is ${err.code}, message is ${err.message}`); 322}) 323``` 324