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