1# @ohos.enterprise.dateTimeManager (系统时间管理) 2 3本模块提供系统时间管理能力。 4 5> **说明**: 6> 7> 本模块首批接口从API version 9 开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 8> 9> 本模块接口仅可在Stage模型下使用。 10> 11> 本模块接口仅对[设备管理应用](enterpriseDeviceManagement-overview.md#基本概念)开放,需将[设备管理应用激活](js-apis-enterprise-adminManager.md#adminmanagerenableadmin)后调用,实现相应功能。 12 13## 导入模块 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 23指定设备管理应用设置系统时间。使用callback异步回调。 24 25**需要权限:** ohos.permission.ENTERPRISE_SET_DATETIME 26 27**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 28 29**系统API**: 此接口为系统接口。 30 31**参数:** 32 33| 参数名 | 类型 | 必填 | 说明 | 34| ----- | ----------------------------------- | ---- | ------- | 35| admin | [Want](js-apis-app-ability-want.md) | 是 | 设备管理应用。 | 36| time | number | 是 | 时间戳(ms)。 | 37| callback | AsyncCallback\<void> | 是 | 回调函数。当接口调用成功,err为null,否则为错误对象。 | 38 39**错误码**: 40 41以下错误码的详细介绍请参见[企业设备管理错误码](../errorcodes/errorcode-enterpriseDeviceManager.md) 42 43| 错误码ID | 错误信息 | 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**示例:** 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 70指定设备管理应用设置系统时间。使用Promise异步回调。 71 72**需要权限:** ohos.permission.ENTERPRISE_SET_DATETIME 73 74**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 75 76**系统API**: 此接口为系统接口。 77 78**参数:** 79 80| 参数名 | 类型 | 必填 | 说明 | 81| ----- | ----------------------------------- | ---- | ------- | 82| admin | [Want](js-apis-app-ability-want.md) | 是 | 设备管理应用。 | 83| time | number | 是 | 时间戳(ms)。 | 84 85**返回值:** 86 87| 类型 | 说明 | 88| ----- | ----------------------------------- | 89| Promise\<void> | Promise对象。无返回结果的Promise对象。 | 90 91**错误码**: 92 93以下错误码的详细介绍请参见[企业设备管理错误码](../errorcodes/errorcode-enterpriseDeviceManager.md) 94 95| 错误码ID | 错误信息 | 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**示例:** 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 121指定设备管理应用禁止设备修改系统时间。使用callback异步回调。 122 123**需要权限:** ohos.permission.ENTERPRISE_SET_DATETIME 124 125**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 126 127**系统API**: 此接口为系统接口。 128 129**参数:** 130 131| 参数名 | 类型 | 必填 | 说明 | 132| ----- | ----------------------------------- | ---- | ------- | 133| admin | [Want](js-apis-app-ability-want.md) | 是 | 设备管理应用。 | 134| disallow | boolean | 是 | true 表示禁止修改系统时间,false表示允许修改系统时间。 | 135| callback | AsyncCallback\<void> | 是 | 回调函数。当接口调用成功,err为null,否则为错误对象。 | 136 137**错误码**: 138 139以下错误码的详细介绍请参见[企业设备管理错误码](../errorcodes/errorcode-enterpriseDeviceManager.md) 140 141| 错误码ID | 错误信息 | 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**示例:** 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 168指定设备管理应用禁止设备修改系统时间。使用Promise异步回调。 169 170**需要权限:** ohos.permission.ENTERPRISE_SET_DATETIME 171 172**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 173 174**系统API**: 此接口为系统接口。 175 176**参数:** 177 178| 参数名 | 类型 | 必填 | 说明 | 179| ----- | ----------------------------------- | ---- | ------- | 180| admin | [Want](js-apis-app-ability-want.md) | 是 | 设备管理应用。 | 181| disallow | boolean | 是 | true 表示禁止修改系统时间,false表示允许修改系统时间。 | 182 183**返回值:** 184 185| 类型 | 说明 | 186| ----- | ----------------------------------- | 187| Promise\<void> | 无返回结果的Promise对象。当指定设备管理应用禁止设备修改系统时间失败时,抛出错误对象。 | 188 189**错误码**: 190 191以下错误码的详细介绍请参见[企业设备管理错误码](../errorcodes/errorcode-enterpriseDeviceManager.md) 192 193| 错误码ID | 错误信息 | 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**示例:** 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 219指定设备管理应用查询设备是否允许修改系统时间。使用callback异步回调。 220 221**需要权限:** ohos.permission.ENTERPRISE_SET_DATETIME 222 223**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 224 225**系统API**: 此接口为系统接口。 226 227**参数:** 228 229| 参数名 | 类型 | 必填 | 说明 | 230| ----- | ----------------------------------- | ---- | ------- | 231| admin | [Want](js-apis-app-ability-want.md) | 是 | 设备管理应用。 | 232| callback | AsyncCallback\<boolean> | 是 | 回调函数,callbac方式返回是否禁止修改系统时间策略,true表示禁止修改系统时间,否则表示允许修改系统时间。 | 233 234**错误码**: 235 236以下错误码的详细介绍请参见[企业设备管理错误码](../errorcodes/errorcode-enterpriseDeviceManager.md) 237 238| 错误码ID | 错误信息 | 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**示例:** 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 265指定设备管理应用查询设备是否允许修改系统时间。使用Promise异步回调。 266 267**需要权限:** ohos.permission.ENTERPRISE_SET_DATETIME 268 269**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 270 271**系统API**: 此接口为系统接口。 272 273**参数:** 274 275| 参数名 | 类型 | 必填 | 说明 | 276| ----- | ----------------------------------- | ---- | ------- | 277| admin | [Want](js-apis-app-ability-want.md) | 是 | 设备管理应用。 | 278 279**返回值:** 280 281| 类型 | 说明 | 282| ----- | ----------------------------------- | 283| Promise\<boolean> | Promise对象。promise方式返回是否禁止修改系统时间策略,true表示禁止修改系统时间,否则表示允许修改系统时间。 | 284 285**错误码**: 286 287以下错误码的详细介绍请参见[企业设备管理错误码](../errorcodes/errorcode-enterpriseDeviceManager.md) 288 289| 错误码ID | 错误信息 | 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**示例:** 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```