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