1e41f4b71Sopenharmony_ci# @ohos.systemDateTime (System Time and Time Zone)
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ciThe **systemTime** 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.getCurrentTime<sup>(deprecated)</sup>
27e41f4b71Sopenharmony_ci
28e41f4b71Sopenharmony_cigetCurrentTime(isNano: boolean, callback: AsyncCallback&lt;number&gt;): void
29e41f4b71Sopenharmony_ci
30e41f4b71Sopenharmony_ciObtains the time elapsed since the Unix epoch. This API uses an asynchronous callback to return the result.
31e41f4b71Sopenharmony_ci
32e41f4b71Sopenharmony_ci> **NOTE**
33e41f4b71Sopenharmony_ci>
34e41f4b71Sopenharmony_ci> This API is deprecated since API version 12. Use [systemDateTime.getTime<sup>10+</sup>](#systemdatetimegettime10) instead.
35e41f4b71Sopenharmony_ci
36e41f4b71Sopenharmony_ci**System capability**: SystemCapability.MiscServices.Time
37e41f4b71Sopenharmony_ci
38e41f4b71Sopenharmony_ci**Parameters**
39e41f4b71Sopenharmony_ci
40e41f4b71Sopenharmony_ci| Name  | Type      | Mandatory| Description                            |
41e41f4b71Sopenharmony_ci| -------- | -------------- | ---- | ------------------ |
42e41f4b71Sopenharmony_ci| isNano   | boolean                     | Yes  | Whether the time to return is in nanoseconds.<br>- **true**: in nanoseconds.<br>- **false**: in milliseconds.|
43e41f4b71Sopenharmony_ci| callback | AsyncCallback&lt;number&gt; | Yes  | Callback used to return the time elapsed since the Unix epoch.        |
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| 401       | Parameter error. Possible causes: 1.Incorrect parameter types. |
52e41f4b71Sopenharmony_ci
53e41f4b71Sopenharmony_ci**Example**
54e41f4b71Sopenharmony_ci
55e41f4b71Sopenharmony_ci```ts
56e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
57e41f4b71Sopenharmony_ci
58e41f4b71Sopenharmony_citry {
59e41f4b71Sopenharmony_ci  systemDateTime.getCurrentTime(true, (error: BusinessError, time: number) => {
60e41f4b71Sopenharmony_ci    if (error) {
61e41f4b71Sopenharmony_ci      console.info(`Failed to get currentTime. message: ${error.message}, code: ${error.code}`);
62e41f4b71Sopenharmony_ci      return;
63e41f4b71Sopenharmony_ci    }
64e41f4b71Sopenharmony_ci    console.info(`Succeeded in getting currentTime : ${time}`);
65e41f4b71Sopenharmony_ci  });
66e41f4b71Sopenharmony_ci} catch(e) {
67e41f4b71Sopenharmony_ci  let error = e as BusinessError;
68e41f4b71Sopenharmony_ci  console.info(`Failed to get currentTime. message: ${error.message}, code: ${error.code}`);
69e41f4b71Sopenharmony_ci}
70e41f4b71Sopenharmony_ci```
71e41f4b71Sopenharmony_ci
72e41f4b71Sopenharmony_ci## systemDateTime.getCurrentTime<sup>(deprecated)</sup>
73e41f4b71Sopenharmony_ci
74e41f4b71Sopenharmony_cigetCurrentTime(callback: AsyncCallback&lt;number&gt;): void
75e41f4b71Sopenharmony_ci
76e41f4b71Sopenharmony_ciObtains the time elapsed since the Unix epoch. This API uses an asynchronous callback to return the result.
77e41f4b71Sopenharmony_ci
78e41f4b71Sopenharmony_ci> **NOTE**
79e41f4b71Sopenharmony_ci>
80e41f4b71Sopenharmony_ci> This API is deprecated since API version 12. Use [systemDateTime.getTime<sup>10+</sup>](#systemdatetimegettime10) instead.
81e41f4b71Sopenharmony_ci
82e41f4b71Sopenharmony_ci**System capability**: SystemCapability.MiscServices.Time
83e41f4b71Sopenharmony_ci
84e41f4b71Sopenharmony_ci**Parameters**
85e41f4b71Sopenharmony_ci
86e41f4b71Sopenharmony_ci| Name  | Type              | Mandatory| Description                           |
87e41f4b71Sopenharmony_ci| -------- | ----------- | ---- | ---------------------------------- |
88e41f4b71Sopenharmony_ci| callback | AsyncCallback&lt;number&gt; | Yes  | Callback used to return the time elapsed since the Unix epoch, in milliseconds.        |
89e41f4b71Sopenharmony_ci
90e41f4b71Sopenharmony_ci**Error codes**
91e41f4b71Sopenharmony_ci
92e41f4b71Sopenharmony_ciFor details about the error codes, see [Time and Time Zone Service Error Codes](./errorcode-time.md).
93e41f4b71Sopenharmony_ci
94e41f4b71Sopenharmony_ci| ID   | Error Message                                                             |
95e41f4b71Sopenharmony_ci|----------|-------------------------------------------------------------------|
96e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1.Incorrect parameter types. |
97e41f4b71Sopenharmony_ci
98e41f4b71Sopenharmony_ci**Example**
99e41f4b71Sopenharmony_ci
100e41f4b71Sopenharmony_ci```ts
101e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
102e41f4b71Sopenharmony_ci
103e41f4b71Sopenharmony_citry {
104e41f4b71Sopenharmony_ci  systemDateTime.getCurrentTime((error: BusinessError, time: number) => {
105e41f4b71Sopenharmony_ci    if (error) {
106e41f4b71Sopenharmony_ci      console.info(`Failed to get currentTime. message: ${error.message}, code: ${error.code}`);
107e41f4b71Sopenharmony_ci      return;
108e41f4b71Sopenharmony_ci    }
109e41f4b71Sopenharmony_ci    console.info(`Succeeded in getting currentTime : ${time}`);
110e41f4b71Sopenharmony_ci  });
111e41f4b71Sopenharmony_ci} catch(e) {
112e41f4b71Sopenharmony_ci  let error = e as BusinessError;
113e41f4b71Sopenharmony_ci  console.info(`Failed to get currentTime. message: ${error.message}, code: ${error.code}`);
114e41f4b71Sopenharmony_ci}
115e41f4b71Sopenharmony_ci```
116e41f4b71Sopenharmony_ci
117e41f4b71Sopenharmony_ci## systemDateTime.getCurrentTime<sup>(deprecated)</sup>
118e41f4b71Sopenharmony_ci
119e41f4b71Sopenharmony_cigetCurrentTime(isNano?: boolean): Promise&lt;number&gt;
120e41f4b71Sopenharmony_ci
121e41f4b71Sopenharmony_ciObtains the time elapsed since the Unix epoch. This API uses a promise to return the result.
122e41f4b71Sopenharmony_ci
123e41f4b71Sopenharmony_ci> **NOTE**
124e41f4b71Sopenharmony_ci>
125e41f4b71Sopenharmony_ci> This API is deprecated since API version 12. Use [systemDateTime.getTime<sup>10+</sup>](#systemdatetimegettime10) instead.
126e41f4b71Sopenharmony_ci
127e41f4b71Sopenharmony_ci**System capability**: SystemCapability.MiscServices.Time
128e41f4b71Sopenharmony_ci
129e41f4b71Sopenharmony_ci**Parameters**
130e41f4b71Sopenharmony_ci
131e41f4b71Sopenharmony_ci| Name| Type   | Mandatory| Description                    |
132e41f4b71Sopenharmony_ci| ------ | ------- | ---- | ------------------------- |
133e41f4b71Sopenharmony_ci| isNano | boolean | No  | Whether the time to return is in nanoseconds. The default value is **false**.<br>- **true**: in nanoseconds.<br>- **false**: in milliseconds.|
134e41f4b71Sopenharmony_ci
135e41f4b71Sopenharmony_ci**Return value**
136e41f4b71Sopenharmony_ci
137e41f4b71Sopenharmony_ci| Type       | Description                              |
138e41f4b71Sopenharmony_ci| --------------------- | --------------------------- |
139e41f4b71Sopenharmony_ci| Promise&lt;number&gt; | Promise used to return the timestamp that has elapsed since the Unix epoch.|
140e41f4b71Sopenharmony_ci
141e41f4b71Sopenharmony_ci**Error codes**
142e41f4b71Sopenharmony_ci
143e41f4b71Sopenharmony_ciFor details about the error codes, see [Time and Time Zone Service Error Codes](./errorcode-time.md).
144e41f4b71Sopenharmony_ci
145e41f4b71Sopenharmony_ci| ID  | Error Message                                                             |
146e41f4b71Sopenharmony_ci|---------|-------------------------------------------------------------------|
147e41f4b71Sopenharmony_ci| 401     | Parameter error. Possible causes: 1.Incorrect parameter types. |
148e41f4b71Sopenharmony_ci
149e41f4b71Sopenharmony_ci**Example**
150e41f4b71Sopenharmony_ci
151e41f4b71Sopenharmony_ci```ts
152e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
153e41f4b71Sopenharmony_ci
154e41f4b71Sopenharmony_citry {
155e41f4b71Sopenharmony_ci  systemDateTime.getCurrentTime().then((time: number) => {
156e41f4b71Sopenharmony_ci    console.info(`Succeeded in getting currentTime : ${time}`);
157e41f4b71Sopenharmony_ci  }).catch((error: BusinessError) => {
158e41f4b71Sopenharmony_ci    console.info(`Failed to get currentTime. message: ${error.message}, code: ${error.code}`);
159e41f4b71Sopenharmony_ci  });
160e41f4b71Sopenharmony_ci} catch(e) {
161e41f4b71Sopenharmony_ci  let error = e as BusinessError;
162e41f4b71Sopenharmony_ci  console.info(`Failed to get currentTime. message: ${error.message}, code: ${error.code}`);
163e41f4b71Sopenharmony_ci}
164e41f4b71Sopenharmony_ci```
165e41f4b71Sopenharmony_ci
166e41f4b71Sopenharmony_ci## systemDateTime.getRealActiveTime<sup>(deprecated)</sup>
167e41f4b71Sopenharmony_ci
168e41f4b71Sopenharmony_cigetRealActiveTime(isNano: boolean, callback: AsyncCallback&lt;number&gt;): void
169e41f4b71Sopenharmony_ci
170e41f4b71Sopenharmony_ciObtains the time elapsed since system startup, excluding the deep sleep time. This API uses an asynchronous callback to return the result.
171e41f4b71Sopenharmony_ci
172e41f4b71Sopenharmony_ci> **NOTE**
173e41f4b71Sopenharmony_ci>
174e41f4b71Sopenharmony_ci> This API is deprecated since API version 12. Use [systemDateTime.getUptime<sup>10+</sup>](#systemdatetimegetuptime10) instead.
175e41f4b71Sopenharmony_ci
176e41f4b71Sopenharmony_ci**System capability**: SystemCapability.MiscServices.Time
177e41f4b71Sopenharmony_ci
178e41f4b71Sopenharmony_ci**Parameters**
179e41f4b71Sopenharmony_ci
180e41f4b71Sopenharmony_ci| Name  | Type                       | Mandatory| Description  |
181e41f4b71Sopenharmony_ci| -------- | ---------- | ---- | -------------------------- |
182e41f4b71Sopenharmony_ci| isNano   | boolean                     | Yes  | Whether the time to return is in nanoseconds.<br>- **true**: in nanoseconds.<br>- **false**: in milliseconds.|
183e41f4b71Sopenharmony_ci| callback | AsyncCallback&lt;number&gt; | Yes  | Callback used to return the time.|
184e41f4b71Sopenharmony_ci
185e41f4b71Sopenharmony_ci**Error codes**
186e41f4b71Sopenharmony_ci
187e41f4b71Sopenharmony_ciFor details about the error codes, see [Time and Time Zone Service Error Codes](./errorcode-time.md).
188e41f4b71Sopenharmony_ci
189e41f4b71Sopenharmony_ci| ID  | Error Message                                                             |
190e41f4b71Sopenharmony_ci|---------|-------------------------------------------------------------------|
191e41f4b71Sopenharmony_ci| 401     | Parameter error. Possible causes: 1.Incorrect parameter types. |
192e41f4b71Sopenharmony_ci
193e41f4b71Sopenharmony_ci**Example**
194e41f4b71Sopenharmony_ci
195e41f4b71Sopenharmony_ci```ts
196e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
197e41f4b71Sopenharmony_ci
198e41f4b71Sopenharmony_citry {
199e41f4b71Sopenharmony_ci  systemDateTime.getRealActiveTime(true, (error: BusinessError, time: number) => {
200e41f4b71Sopenharmony_ci    if (error) {
201e41f4b71Sopenharmony_ci      console.info(`Failed to get real active time. message: ${error.message}, code: ${error.code}`);
202e41f4b71Sopenharmony_ci      return;
203e41f4b71Sopenharmony_ci    }
204e41f4b71Sopenharmony_ci    console.info(`Succeeded in getting real active time : ${time}`);
205e41f4b71Sopenharmony_ci  });
206e41f4b71Sopenharmony_ci} catch(e) {
207e41f4b71Sopenharmony_ci  let error = e as BusinessError;
208e41f4b71Sopenharmony_ci  console.info(`Failed to get real active time. message: ${error.message}, code: ${error.code}`);
209e41f4b71Sopenharmony_ci}
210e41f4b71Sopenharmony_ci```
211e41f4b71Sopenharmony_ci
212e41f4b71Sopenharmony_ci## systemDateTime.getRealActiveTime<sup>(deprecated)</sup>
213e41f4b71Sopenharmony_ci
214e41f4b71Sopenharmony_cigetRealActiveTime(callback: AsyncCallback&lt;number&gt;): void
215e41f4b71Sopenharmony_ci
216e41f4b71Sopenharmony_ciObtains the time elapsed since system startup, excluding the deep sleep time. This API uses an asynchronous callback to return the result.
217e41f4b71Sopenharmony_ci
218e41f4b71Sopenharmony_ci> **NOTE**
219e41f4b71Sopenharmony_ci>
220e41f4b71Sopenharmony_ci> This API is deprecated since API version 12. Use [systemDateTime.getUptime<sup>10+</sup>](#systemdatetimegetuptime10) instead.
221e41f4b71Sopenharmony_ci
222e41f4b71Sopenharmony_ci**System capability**: SystemCapability.MiscServices.Time
223e41f4b71Sopenharmony_ci
224e41f4b71Sopenharmony_ci**Parameters**
225e41f4b71Sopenharmony_ci
226e41f4b71Sopenharmony_ci| Name  | Type                       | Mandatory| Description   |
227e41f4b71Sopenharmony_ci| -------- | -------------- | ---- | --------------------- |
228e41f4b71Sopenharmony_ci| callback | AsyncCallback&lt;number&gt; | Yes  | Callback used to return the time.|
229e41f4b71Sopenharmony_ci
230e41f4b71Sopenharmony_ci**Error codes**
231e41f4b71Sopenharmony_ci
232e41f4b71Sopenharmony_ciFor details about the error codes, see [Time and Time Zone Service Error Codes](./errorcode-time.md).
233e41f4b71Sopenharmony_ci
234e41f4b71Sopenharmony_ci| ID  | Error Message                                                             |
235e41f4b71Sopenharmony_ci|---------|-------------------------------------------------------------------|
236e41f4b71Sopenharmony_ci| 401     | Parameter error. Possible causes: 1.Incorrect parameter types. |
237e41f4b71Sopenharmony_ci
238e41f4b71Sopenharmony_ci**Example**
239e41f4b71Sopenharmony_ci
240e41f4b71Sopenharmony_ci```ts
241e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
242e41f4b71Sopenharmony_ci
243e41f4b71Sopenharmony_citry {
244e41f4b71Sopenharmony_ci  systemDateTime.getRealActiveTime((error: BusinessError, time: number) => {
245e41f4b71Sopenharmony_ci    if (error) {
246e41f4b71Sopenharmony_ci      console.info(`Failed to get real active time. message: ${error.message}, code: ${error.code}`);
247e41f4b71Sopenharmony_ci      return;
248e41f4b71Sopenharmony_ci    }
249e41f4b71Sopenharmony_ci    console.info(`Succeeded in getting real active time : ${time}`);
250e41f4b71Sopenharmony_ci  });
251e41f4b71Sopenharmony_ci} catch(e) {
252e41f4b71Sopenharmony_ci  let error = e as BusinessError;
253e41f4b71Sopenharmony_ci  console.info(`Failed to get real active time. message: ${error.message}, code: ${error.code}`);
254e41f4b71Sopenharmony_ci}
255e41f4b71Sopenharmony_ci```
256e41f4b71Sopenharmony_ci
257e41f4b71Sopenharmony_ci## systemDateTime.getRealActiveTime<sup>(deprecated)</sup>
258e41f4b71Sopenharmony_ci
259e41f4b71Sopenharmony_cigetRealActiveTime(isNano?: boolean): Promise&lt;number&gt;
260e41f4b71Sopenharmony_ci
261e41f4b71Sopenharmony_ciObtains the time elapsed since system startup, excluding the deep sleep time. This API uses a promise to return the result.
262e41f4b71Sopenharmony_ci
263e41f4b71Sopenharmony_ci> **NOTE**
264e41f4b71Sopenharmony_ci>
265e41f4b71Sopenharmony_ci> This API is deprecated since API version 12. Use [systemDateTime.getUptime<sup>10+</sup>](#systemdatetimegetuptime10) instead.
266e41f4b71Sopenharmony_ci
267e41f4b71Sopenharmony_ci**System capability**: SystemCapability.MiscServices.Time
268e41f4b71Sopenharmony_ci
269e41f4b71Sopenharmony_ci**Parameters**
270e41f4b71Sopenharmony_ci
271e41f4b71Sopenharmony_ci| Name| Type   | Mandatory| Description                             |
272e41f4b71Sopenharmony_ci| ------ | ------- | ---- | ----------------------------------- |
273e41f4b71Sopenharmony_ci| isNano | boolean | No  | Whether the time to return is in nanoseconds. The default value is **false**.<br>- **true**: in nanoseconds.<br>- **false**: in milliseconds.|
274e41f4b71Sopenharmony_ci
275e41f4b71Sopenharmony_ci**Return value**
276e41f4b71Sopenharmony_ci
277e41f4b71Sopenharmony_ci| Type                 | Description        |
278e41f4b71Sopenharmony_ci| -------------- | -------------------------------- |
279e41f4b71Sopenharmony_ci| Promise&lt;number&gt; | Promise used to return the time elapsed since system startup, excluding the deep sleep time.|
280e41f4b71Sopenharmony_ci
281e41f4b71Sopenharmony_ci**Error codes**
282e41f4b71Sopenharmony_ci
283e41f4b71Sopenharmony_ciFor details about the error codes, see [Time and Time Zone Service Error Codes](./errorcode-time.md).
284e41f4b71Sopenharmony_ci
285e41f4b71Sopenharmony_ci| ID  | Error Message                                                             |
286e41f4b71Sopenharmony_ci|---------|-------------------------------------------------------------------|
287e41f4b71Sopenharmony_ci| 401     | Parameter error. Possible causes: 1.Incorrect parameter types. |
288e41f4b71Sopenharmony_ci
289e41f4b71Sopenharmony_ci**Example**
290e41f4b71Sopenharmony_ci
291e41f4b71Sopenharmony_ci```ts
292e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
293e41f4b71Sopenharmony_ci
294e41f4b71Sopenharmony_citry {
295e41f4b71Sopenharmony_ci  systemDateTime.getRealActiveTime().then((time: number) => {
296e41f4b71Sopenharmony_ci    console.info(`Succeeded in getting real active time : ${time}`);
297e41f4b71Sopenharmony_ci  }).catch((error: BusinessError) => {
298e41f4b71Sopenharmony_ci    console.info(`Failed to get real active time. message: ${error.message}, code: ${error.code}`);
299e41f4b71Sopenharmony_ci  });
300e41f4b71Sopenharmony_ci} catch(e) {
301e41f4b71Sopenharmony_ci  let error = e as BusinessError;
302e41f4b71Sopenharmony_ci  console.info(`Failed to get real active time. message: ${error.message}, code: ${error.code}`);
303e41f4b71Sopenharmony_ci}
304e41f4b71Sopenharmony_ci```
305e41f4b71Sopenharmony_ci
306e41f4b71Sopenharmony_ci## systemDateTime.getRealTime<sup>(deprecated)</sup>
307e41f4b71Sopenharmony_ci
308e41f4b71Sopenharmony_cigetRealTime(isNano: boolean, callback: AsyncCallback&lt;number&gt;): void
309e41f4b71Sopenharmony_ci
310e41f4b71Sopenharmony_ciObtains the time elapsed since system startup, including the deep sleep time. This API uses an asynchronous callback to return the result.
311e41f4b71Sopenharmony_ci
312e41f4b71Sopenharmony_ci> **NOTE**
313e41f4b71Sopenharmony_ci>
314e41f4b71Sopenharmony_ci> This API is deprecated since API version 12. Use [systemDateTime.getUptime<sup>10+</sup>](#systemdatetimegetuptime10) instead.
315e41f4b71Sopenharmony_ci
316e41f4b71Sopenharmony_ci**System capability**: SystemCapability.MiscServices.Time
317e41f4b71Sopenharmony_ci
318e41f4b71Sopenharmony_ci**Parameters**
319e41f4b71Sopenharmony_ci
320e41f4b71Sopenharmony_ci| Name  | Type                       | Mandatory| Description  |
321e41f4b71Sopenharmony_ci| -------- | --------------- | ---- | ------------------------------- |
322e41f4b71Sopenharmony_ci| isNano   | boolean                     | Yes  | Whether the time to return is in nanoseconds.<br>- **true**: in nanoseconds.<br>- **false**: in milliseconds.|
323e41f4b71Sopenharmony_ci| callback | AsyncCallback&lt;number&gt; | Yes  | Callback used to return the time.  |
324e41f4b71Sopenharmony_ci
325e41f4b71Sopenharmony_ci**Error codes**
326e41f4b71Sopenharmony_ci
327e41f4b71Sopenharmony_ciFor details about the error codes, see [Time and Time Zone Service Error Codes](./errorcode-time.md).
328e41f4b71Sopenharmony_ci
329e41f4b71Sopenharmony_ci| ID  | Error Message                                                             |
330e41f4b71Sopenharmony_ci|---------|-------------------------------------------------------------------|
331e41f4b71Sopenharmony_ci| 401     | Parameter error. Possible causes: 1.Incorrect parameter types. |
332e41f4b71Sopenharmony_ci
333e41f4b71Sopenharmony_ci**Example**
334e41f4b71Sopenharmony_ci
335e41f4b71Sopenharmony_ci```ts
336e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
337e41f4b71Sopenharmony_ci
338e41f4b71Sopenharmony_citry {
339e41f4b71Sopenharmony_ci  systemDateTime.getRealTime(true, (error: BusinessError, time: number) => {
340e41f4b71Sopenharmony_ci    if (error) {
341e41f4b71Sopenharmony_ci      console.info(`Failed to get real time. message: ${error.message}, code: ${error.code}`);
342e41f4b71Sopenharmony_ci      return;
343e41f4b71Sopenharmony_ci    }
344e41f4b71Sopenharmony_ci    console.info(`Succeeded in getting real time : ${time}`);
345e41f4b71Sopenharmony_ci  });
346e41f4b71Sopenharmony_ci} catch(e) {
347e41f4b71Sopenharmony_ci  let error = e as BusinessError;
348e41f4b71Sopenharmony_ci  console.info(`Failed to get real time. message: ${error.message}, code: ${error.code}`);
349e41f4b71Sopenharmony_ci}
350e41f4b71Sopenharmony_ci```
351e41f4b71Sopenharmony_ci
352e41f4b71Sopenharmony_ci## systemDateTime.getRealTime<sup>(deprecated)</sup>
353e41f4b71Sopenharmony_ci
354e41f4b71Sopenharmony_cigetRealTime(callback: AsyncCallback&lt;number&gt;): void
355e41f4b71Sopenharmony_ci
356e41f4b71Sopenharmony_ciObtains the time elapsed since system startup, including the deep sleep time. This API uses an asynchronous callback to return the result.
357e41f4b71Sopenharmony_ci
358e41f4b71Sopenharmony_ci> **NOTE**
359e41f4b71Sopenharmony_ci>
360e41f4b71Sopenharmony_ci> This API is deprecated since API version 12. Use [systemDateTime.getUptime<sup>10+</sup>](#systemdatetimegetuptime10) instead.
361e41f4b71Sopenharmony_ci
362e41f4b71Sopenharmony_ci**System capability**: SystemCapability.MiscServices.Time
363e41f4b71Sopenharmony_ci
364e41f4b71Sopenharmony_ci**Parameters**
365e41f4b71Sopenharmony_ci
366e41f4b71Sopenharmony_ci| Name  | Type                       | Mandatory| Description     |
367e41f4b71Sopenharmony_ci| -------- | --------- | ---- | --------------------------- |
368e41f4b71Sopenharmony_ci| callback | AsyncCallback&lt;number&gt; | Yes  | Callback used to return the time.  |
369e41f4b71Sopenharmony_ci
370e41f4b71Sopenharmony_ci**Error codes**
371e41f4b71Sopenharmony_ci
372e41f4b71Sopenharmony_ciFor details about the error codes, see [Time and Time Zone Service Error Codes](./errorcode-time.md).
373e41f4b71Sopenharmony_ci
374e41f4b71Sopenharmony_ci| ID  | Error Message                                                             |
375e41f4b71Sopenharmony_ci|---------|-------------------------------------------------------------------|
376e41f4b71Sopenharmony_ci| 401     | Parameter error. Possible causes: 1.Incorrect parameter types. |
377e41f4b71Sopenharmony_ci
378e41f4b71Sopenharmony_ci**Example**
379e41f4b71Sopenharmony_ci
380e41f4b71Sopenharmony_ci```ts
381e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
382e41f4b71Sopenharmony_ci
383e41f4b71Sopenharmony_citry {
384e41f4b71Sopenharmony_ci  systemDateTime.getRealTime((error: BusinessError, time: number) => {
385e41f4b71Sopenharmony_ci    if (error) {
386e41f4b71Sopenharmony_ci      console.info(`Failed to get real time. message: ${error.message}, code: ${error.code}`);
387e41f4b71Sopenharmony_ci      return;
388e41f4b71Sopenharmony_ci    }
389e41f4b71Sopenharmony_ci    console.info(`Succeeded in getting real time : ${time}`);
390e41f4b71Sopenharmony_ci  });
391e41f4b71Sopenharmony_ci} catch(e) {
392e41f4b71Sopenharmony_ci  let error = e as BusinessError;
393e41f4b71Sopenharmony_ci  console.info(`Failed to get real time. message: ${error.message}, code: ${error.code}`);
394e41f4b71Sopenharmony_ci}
395e41f4b71Sopenharmony_ci```
396e41f4b71Sopenharmony_ci
397e41f4b71Sopenharmony_ci## systemDateTime.getRealTime<sup>(deprecated)</sup>
398e41f4b71Sopenharmony_ci
399e41f4b71Sopenharmony_cigetRealTime(isNano?: boolean): Promise&lt;number&gt;
400e41f4b71Sopenharmony_ci
401e41f4b71Sopenharmony_ciObtains the time elapsed since system startup, including the deep sleep time. This API uses a promise to return the result.
402e41f4b71Sopenharmony_ci
403e41f4b71Sopenharmony_ci> **NOTE**
404e41f4b71Sopenharmony_ci>
405e41f4b71Sopenharmony_ci> This API is deprecated since API version 12. Use [systemDateTime.getUptime<sup>10+</sup>](#systemdatetimegetuptime10) instead.
406e41f4b71Sopenharmony_ci
407e41f4b71Sopenharmony_ci**System capability**: SystemCapability.MiscServices.Time
408e41f4b71Sopenharmony_ci
409e41f4b71Sopenharmony_ci**Parameters**
410e41f4b71Sopenharmony_ci
411e41f4b71Sopenharmony_ci| Name| Type   | Mandatory| Description                              |
412e41f4b71Sopenharmony_ci| ------ | ------- | ---- | ------------------------------- |
413e41f4b71Sopenharmony_ci| isNano | boolean | No  | Whether the time to return is in nanoseconds. The default value is **false**.<br>- **true**: in nanoseconds.<br>- **false**: in milliseconds.|
414e41f4b71Sopenharmony_ci
415e41f4b71Sopenharmony_ci**Return value**
416e41f4b71Sopenharmony_ci
417e41f4b71Sopenharmony_ci| Type                 | Description      |
418e41f4b71Sopenharmony_ci| --------------------- | ------------------------------- |
419e41f4b71Sopenharmony_ci| Promise&lt;number&gt; | Promise used to return the time elapsed since system startup, including the deep sleep time.|
420e41f4b71Sopenharmony_ci
421e41f4b71Sopenharmony_ci**Error codes**
422e41f4b71Sopenharmony_ci
423e41f4b71Sopenharmony_ciFor details about the error codes, see [Time and Time Zone Service Error Codes](./errorcode-time.md).
424e41f4b71Sopenharmony_ci
425e41f4b71Sopenharmony_ci| ID  | Error Message                                                             |
426e41f4b71Sopenharmony_ci|---------|-------------------------------------------------------------------|
427e41f4b71Sopenharmony_ci| 401     | Parameter error. Possible causes: 1.Incorrect parameter types. |
428e41f4b71Sopenharmony_ci
429e41f4b71Sopenharmony_ci**Example**
430e41f4b71Sopenharmony_ci
431e41f4b71Sopenharmony_ci```ts
432e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
433e41f4b71Sopenharmony_ci
434e41f4b71Sopenharmony_citry {
435e41f4b71Sopenharmony_ci  systemDateTime.getRealTime().then((time: number) => {
436e41f4b71Sopenharmony_ci    console.info(`Succeeded in getting real time : ${time}`);
437e41f4b71Sopenharmony_ci  }).catch((error: BusinessError) => {
438e41f4b71Sopenharmony_ci    console.info(`Failed to get real time. message: ${error.message}, code: ${error.code}`);
439e41f4b71Sopenharmony_ci  });
440e41f4b71Sopenharmony_ci} catch(e) {
441e41f4b71Sopenharmony_ci  let error = e as BusinessError;
442e41f4b71Sopenharmony_ci  console.info(`Failed to get real time. message: ${error.message}, code: ${error.code}`);
443e41f4b71Sopenharmony_ci}
444e41f4b71Sopenharmony_ci```
445e41f4b71Sopenharmony_ci
446e41f4b71Sopenharmony_ci## systemDateTime.getTime<sup>10+</sup>
447e41f4b71Sopenharmony_ci
448e41f4b71Sopenharmony_cigetTime(isNanoseconds?: boolean): number
449e41f4b71Sopenharmony_ci
450e41f4b71Sopenharmony_ci Obtains the time elapsed since the Unix epoch. This API returns the result synchronously.
451e41f4b71Sopenharmony_ci
452e41f4b71Sopenharmony_ci**System capability**: SystemCapability.MiscServices.Time
453e41f4b71Sopenharmony_ci
454e41f4b71Sopenharmony_ci**Parameters**
455e41f4b71Sopenharmony_ci
456e41f4b71Sopenharmony_ci| Name       | Type   | Mandatory| Description                                                        |
457e41f4b71Sopenharmony_ci| ------------- | ------- | ---- | ------------------------------------------------------------ |
458e41f4b71Sopenharmony_ci| isNanoseconds | boolean | No  | Whether the time to return is in nanoseconds.<br>- **true**: in nanoseconds.<br>- **false**: in milliseconds.<br>The default value is **false**.|
459e41f4b71Sopenharmony_ci
460e41f4b71Sopenharmony_ci**Return value**
461e41f4b71Sopenharmony_ci
462e41f4b71Sopenharmony_ci| Type  | Description                      |
463e41f4b71Sopenharmony_ci| ------ | -------------------------- |
464e41f4b71Sopenharmony_ci| number | Time elapsed since the Unix epoch.|
465e41f4b71Sopenharmony_ci
466e41f4b71Sopenharmony_ci**Example**
467e41f4b71Sopenharmony_ci
468e41f4b71Sopenharmony_ci```ts
469e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
470e41f4b71Sopenharmony_ci
471e41f4b71Sopenharmony_citry {
472e41f4b71Sopenharmony_ci  let time = systemDateTime.getTime(true)
473e41f4b71Sopenharmony_ci} catch(e) {
474e41f4b71Sopenharmony_ci  let error = e as BusinessError;
475e41f4b71Sopenharmony_ci  console.info(`Failed to get time. message: ${error.message}, code: ${error.code}`);
476e41f4b71Sopenharmony_ci}
477e41f4b71Sopenharmony_ci```
478e41f4b71Sopenharmony_ci
479e41f4b71Sopenharmony_ci## systemDateTime.getUptime<sup>10+</sup>
480e41f4b71Sopenharmony_ci
481e41f4b71Sopenharmony_cigetUptime(timeType: TimeType, isNanoseconds?: boolean): number
482e41f4b71Sopenharmony_ci
483e41f4b71Sopenharmony_ciObtains the time elapsed since system startup. This API returns the result synchronously.
484e41f4b71Sopenharmony_ci
485e41f4b71Sopenharmony_ci**System capability**: SystemCapability.MiscServices.Time
486e41f4b71Sopenharmony_ci
487e41f4b71Sopenharmony_ci**Parameters**
488e41f4b71Sopenharmony_ci
489e41f4b71Sopenharmony_ci| Name       | Type                   | Mandatory| Description                                                                               |
490e41f4b71Sopenharmony_ci| ------------- | ----------------------- | ---- |-----------------------------------------------------------------------------------|
491e41f4b71Sopenharmony_ci| timeType      | [TimeType](#timetype10) | Yes  | Type of the time to be obtained. The value can only be `STARTUP` or `ACTIVE`.                                                 |
492e41f4b71Sopenharmony_ci| isNanoseconds | boolean                 | No  | Whether the time to return is in nanoseconds.<br>- **true**: in nanoseconds.<br>- **false**: in milliseconds.<br>The default value is **false**.|
493e41f4b71Sopenharmony_ci
494e41f4b71Sopenharmony_ci**Return value**
495e41f4b71Sopenharmony_ci
496e41f4b71Sopenharmony_ci| Type  | Description                      |
497e41f4b71Sopenharmony_ci| ------ | -------------------------- |
498e41f4b71Sopenharmony_ci| number | Time elapsed since system startup.|
499e41f4b71Sopenharmony_ci
500e41f4b71Sopenharmony_ci**Error codes**
501e41f4b71Sopenharmony_ci
502e41f4b71Sopenharmony_ciFor details about the error codes, see [Time and Time Zone Service Error Codes](errorcode-time.md).
503e41f4b71Sopenharmony_ci
504e41f4b71Sopenharmony_ci| ID| Error Message                                                                                                          |
505e41f4b71Sopenharmony_ci| -------- |----------------------------------------------------------------------------------------------------------------|
506e41f4b71Sopenharmony_ci| 401       | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed. This error code was added due to missing issues. |
507e41f4b71Sopenharmony_ci
508e41f4b71Sopenharmony_ci**Example**
509e41f4b71Sopenharmony_ci
510e41f4b71Sopenharmony_ci```ts
511e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
512e41f4b71Sopenharmony_ci
513e41f4b71Sopenharmony_citry {
514e41f4b71Sopenharmony_ci  let time = systemDateTime.getUptime(systemDateTime.TimeType.ACTIVE, false);
515e41f4b71Sopenharmony_ci} catch(e) {
516e41f4b71Sopenharmony_ci  let error = e as BusinessError;
517e41f4b71Sopenharmony_ci  console.info(`Failed to get uptime. message: ${error.message}, code: ${error.code}`);
518e41f4b71Sopenharmony_ci}
519e41f4b71Sopenharmony_ci```
520e41f4b71Sopenharmony_ci
521e41f4b71Sopenharmony_ci## systemDateTime.getDate<sup>(deprecated)</sup>
522e41f4b71Sopenharmony_ci
523e41f4b71Sopenharmony_cigetDate(callback: AsyncCallback&lt;Date&gt;): void
524e41f4b71Sopenharmony_ci
525e41f4b71Sopenharmony_ciObtains the current system date. This API uses an asynchronous callback to return the result.
526e41f4b71Sopenharmony_ci
527e41f4b71Sopenharmony_ci> **NOTE**
528e41f4b71Sopenharmony_ci>
529e41f4b71Sopenharmony_ci> This API is supported since API version 9 and deprecated since API version 10. You are advised to use **new Date()** instead, which returns a **Date** object.
530e41f4b71Sopenharmony_ci
531e41f4b71Sopenharmony_ci**System capability**: SystemCapability.MiscServices.Time
532e41f4b71Sopenharmony_ci
533e41f4b71Sopenharmony_ci**Parameters**
534e41f4b71Sopenharmony_ci
535e41f4b71Sopenharmony_ci| Name  | Type          | Mandatory| Description                  |
536e41f4b71Sopenharmony_ci| -------- | -------------- | ---- | --------------------- |
537e41f4b71Sopenharmony_ci| callback | AsyncCallback&lt;Date&gt; | Yes  | Callback used to return the current system date.|
538e41f4b71Sopenharmony_ci
539e41f4b71Sopenharmony_ci**Error codes**
540e41f4b71Sopenharmony_ci
541e41f4b71Sopenharmony_ciFor details about the error codes, see [Time and Time Zone Service Error Codes](./errorcode-time.md).
542e41f4b71Sopenharmony_ci
543e41f4b71Sopenharmony_ci| ID| Error Message                                                |
544e41f4b71Sopenharmony_ci|-------|------------------------------------------------------|
545e41f4b71Sopenharmony_ci| 401   | Parameter error. Possible causes: 1.System error. |
546e41f4b71Sopenharmony_ci
547e41f4b71Sopenharmony_ci**Example**
548e41f4b71Sopenharmony_ci
549e41f4b71Sopenharmony_ci```ts
550e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
551e41f4b71Sopenharmony_ci
552e41f4b71Sopenharmony_citry {
553e41f4b71Sopenharmony_ci  systemDateTime.getDate((error: BusinessError, date: Date) => {
554e41f4b71Sopenharmony_ci    if (error) {
555e41f4b71Sopenharmony_ci      console.info(`Failed to get date. message: ${error.message}, code: ${error.code}`);
556e41f4b71Sopenharmony_ci      return;
557e41f4b71Sopenharmony_ci    }
558e41f4b71Sopenharmony_ci    console.info(`Succeeded in getting date : ${date}`);;
559e41f4b71Sopenharmony_ci  });
560e41f4b71Sopenharmony_ci} catch(e) {
561e41f4b71Sopenharmony_ci  let error = e as BusinessError;
562e41f4b71Sopenharmony_ci  console.info(`Failed to get date. message: ${error.message}, code: ${error.code}`);
563e41f4b71Sopenharmony_ci}
564e41f4b71Sopenharmony_ci```
565e41f4b71Sopenharmony_ci
566e41f4b71Sopenharmony_ci## systemDateTime.getDate<sup>(deprecated)</sup>
567e41f4b71Sopenharmony_ci
568e41f4b71Sopenharmony_cigetDate(): Promise&lt;Date&gt;
569e41f4b71Sopenharmony_ci
570e41f4b71Sopenharmony_ciObtains the current system date. This API uses a promise to return the result.
571e41f4b71Sopenharmony_ci
572e41f4b71Sopenharmony_ci> **NOTE**
573e41f4b71Sopenharmony_ci>
574e41f4b71Sopenharmony_ci> This API is supported since API version 9 and deprecated since API version 10. You are advised to use **new Date()** instead, which returns a **Date** object.
575e41f4b71Sopenharmony_ci
576e41f4b71Sopenharmony_ci**System capability**: SystemCapability.MiscServices.Time
577e41f4b71Sopenharmony_ci
578e41f4b71Sopenharmony_ci**Return value**
579e41f4b71Sopenharmony_ci
580e41f4b71Sopenharmony_ci| Type               | Description                                     |
581e41f4b71Sopenharmony_ci| ------------------- | ----------------------------------------- |
582e41f4b71Sopenharmony_ci| Promise&lt;Date&gt; | Promise used to return the current system date.|
583e41f4b71Sopenharmony_ci
584e41f4b71Sopenharmony_ci**Error codes**
585e41f4b71Sopenharmony_ci
586e41f4b71Sopenharmony_ciFor details about the error codes, see [Time and Time Zone Service Error Codes](./errorcode-time.md).
587e41f4b71Sopenharmony_ci
588e41f4b71Sopenharmony_ci| ID| Error Message                                                |
589e41f4b71Sopenharmony_ci|-------|------------------------------------------------------|
590e41f4b71Sopenharmony_ci| 401   | Parameter error. Possible causes: 1.System error. |
591e41f4b71Sopenharmony_ci
592e41f4b71Sopenharmony_ci**Example**
593e41f4b71Sopenharmony_ci
594e41f4b71Sopenharmony_ci```ts
595e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
596e41f4b71Sopenharmony_ci
597e41f4b71Sopenharmony_citry {
598e41f4b71Sopenharmony_ci  systemDateTime.getDate().then((date: Date) => {
599e41f4b71Sopenharmony_ci    console.info(`Succeeded in getting date : ${date}`);
600e41f4b71Sopenharmony_ci  }).catch((error: BusinessError) => {
601e41f4b71Sopenharmony_ci    console.info(`Failed to get date. message: ${error.message}, code: ${error.code}`);
602e41f4b71Sopenharmony_ci  });
603e41f4b71Sopenharmony_ci} catch(e) {
604e41f4b71Sopenharmony_ci  let error = e as BusinessError;
605e41f4b71Sopenharmony_ci  console.info(`Failed to get date. message: ${error.message}, code: ${error.code}`);
606e41f4b71Sopenharmony_ci}
607e41f4b71Sopenharmony_ci```
608e41f4b71Sopenharmony_ci
609e41f4b71Sopenharmony_ci## systemDateTime.getTimezone
610e41f4b71Sopenharmony_ci
611e41f4b71Sopenharmony_cigetTimezone(callback: AsyncCallback&lt;string&gt;): void
612e41f4b71Sopenharmony_ci
613e41f4b71Sopenharmony_ciObtains the system time zone. This API uses an asynchronous callback to return the result.
614e41f4b71Sopenharmony_ci
615e41f4b71Sopenharmony_ci**System capability**: SystemCapability.MiscServices.Time
616e41f4b71Sopenharmony_ci
617e41f4b71Sopenharmony_ci**Parameters**
618e41f4b71Sopenharmony_ci
619e41f4b71Sopenharmony_ci| Name  | Type             | Mandatory| Description                |
620e41f4b71Sopenharmony_ci| -------- | --------- | ---- | ------------------------ |
621e41f4b71Sopenharmony_ci| callback | AsyncCallback&lt;string&gt; | Yes  | Callback used to return the system time zone. For details, see [Supported System Time Zones](#supported-system-time-zones).|
622e41f4b71Sopenharmony_ci
623e41f4b71Sopenharmony_ci**Example**
624e41f4b71Sopenharmony_ci
625e41f4b71Sopenharmony_ci```ts
626e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
627e41f4b71Sopenharmony_ci
628e41f4b71Sopenharmony_citry {
629e41f4b71Sopenharmony_ci  systemDateTime.getTimezone((error: BusinessError, data: string) => {
630e41f4b71Sopenharmony_ci    if (error) {
631e41f4b71Sopenharmony_ci      console.info(`Failed to get timezone. message: ${error.message}, code: ${error.code}`);
632e41f4b71Sopenharmony_ci      return;
633e41f4b71Sopenharmony_ci    }
634e41f4b71Sopenharmony_ci    console.info(`Succeeded in get timezone : ${data}`);;
635e41f4b71Sopenharmony_ci  });
636e41f4b71Sopenharmony_ci} catch(e) {
637e41f4b71Sopenharmony_ci  let error = e as BusinessError;
638e41f4b71Sopenharmony_ci  console.info(`Failed to get timezone. message: ${error.message}, code: ${error.code}`);
639e41f4b71Sopenharmony_ci}
640e41f4b71Sopenharmony_ci```
641e41f4b71Sopenharmony_ci
642e41f4b71Sopenharmony_ci## systemDateTime.getTimezone
643e41f4b71Sopenharmony_ci
644e41f4b71Sopenharmony_cigetTimezone(): Promise&lt;string&gt;
645e41f4b71Sopenharmony_ci
646e41f4b71Sopenharmony_ciObtains the system time zone. This API uses a promise to return the result.
647e41f4b71Sopenharmony_ci
648e41f4b71Sopenharmony_ci**System capability**: SystemCapability.MiscServices.Time
649e41f4b71Sopenharmony_ci
650e41f4b71Sopenharmony_ci**Return value**
651e41f4b71Sopenharmony_ci
652e41f4b71Sopenharmony_ci| Type                 | Description                                 |
653e41f4b71Sopenharmony_ci| --------------------- | ------------------------------------- |
654e41f4b71Sopenharmony_ci| Promise&lt;string&gt; | Promise used to return the system time zone. For details, see [Supported System Time Zones](#supported-system-time-zones).|
655e41f4b71Sopenharmony_ci
656e41f4b71Sopenharmony_ci**Example**
657e41f4b71Sopenharmony_ci
658e41f4b71Sopenharmony_ci```ts
659e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
660e41f4b71Sopenharmony_ci
661e41f4b71Sopenharmony_citry {
662e41f4b71Sopenharmony_ci  systemDateTime.getTimezone().then((data: string) => {
663e41f4b71Sopenharmony_ci    console.info(`Succeeded in getting timezone: ${data}`);
664e41f4b71Sopenharmony_ci  }).catch((error: BusinessError) => {
665e41f4b71Sopenharmony_ci    console.info(`Failed to get timezone. message: ${error.message}, code: ${error.code}`);
666e41f4b71Sopenharmony_ci  });
667e41f4b71Sopenharmony_ci} catch(e) {
668e41f4b71Sopenharmony_ci  let error = e as BusinessError;
669e41f4b71Sopenharmony_ci  console.info(`Failed to get timezone. message: ${error.message}, code: ${error.code}`);
670e41f4b71Sopenharmony_ci}
671e41f4b71Sopenharmony_ci```
672e41f4b71Sopenharmony_ci
673e41f4b71Sopenharmony_ci## systemDateTime.getTimezoneSync<sup>10+</sup>
674e41f4b71Sopenharmony_ci
675e41f4b71Sopenharmony_cigetTimezoneSync(): string
676e41f4b71Sopenharmony_ci
677e41f4b71Sopenharmony_ciObtains the system time zone in synchronous mode.
678e41f4b71Sopenharmony_ci
679e41f4b71Sopenharmony_ci**System capability**: SystemCapability.MiscServices.Time
680e41f4b71Sopenharmony_ci
681e41f4b71Sopenharmony_ci**Return value**
682e41f4b71Sopenharmony_ci
683e41f4b71Sopenharmony_ci| Type  | Description                                                      |
684e41f4b71Sopenharmony_ci| ------ | ---------------------------------------------------------- |
685e41f4b71Sopenharmony_ci| string | System time zone. For details, see [Supported System Time Zones](#supported-system-time-zones).|
686e41f4b71Sopenharmony_ci
687e41f4b71Sopenharmony_ci**Example**
688e41f4b71Sopenharmony_ci
689e41f4b71Sopenharmony_ci```ts
690e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
691e41f4b71Sopenharmony_ci
692e41f4b71Sopenharmony_citry {
693e41f4b71Sopenharmony_ci  let timezone = systemDateTime.getTimezoneSync();
694e41f4b71Sopenharmony_ci} catch(e) {
695e41f4b71Sopenharmony_ci  let error = e as BusinessError;
696e41f4b71Sopenharmony_ci  console.info(`Failed to get timezone. message: ${error.message}, code: ${error.code}`);
697e41f4b71Sopenharmony_ci}
698e41f4b71Sopenharmony_ci```
699e41f4b71Sopenharmony_ci
700e41f4b71Sopenharmony_ci## Supported System Time Zones
701e41f4b71Sopenharmony_ci
702e41f4b71Sopenharmony_ciThe following table lists the supported system time zones and the respective offset (unit: h) between each time zone and time zone 0.
703e41f4b71Sopenharmony_ci
704e41f4b71Sopenharmony_ci| Time Zone                          | Offset        |
705e41f4b71Sopenharmony_ci| ------------------------------ | --------------------- |
706e41f4b71Sopenharmony_ci| Antarctica/McMurdo             | 12                    |
707e41f4b71Sopenharmony_ci| America/Argentina/Buenos_Aires | -3                    |
708e41f4b71Sopenharmony_ci| Australia/Sydney               | 10                    |
709e41f4b71Sopenharmony_ci| America/Noronha                | -2                    |
710e41f4b71Sopenharmony_ci| America/St_Johns               | -3                    |
711e41f4b71Sopenharmony_ci| Africa/Kinshasa                | 1                     |
712e41f4b71Sopenharmony_ci| America/Santiago               | -3                    |
713e41f4b71Sopenharmony_ci| Asia/Shanghai                  | 8                     |
714e41f4b71Sopenharmony_ci| Asia/Nicosia                   | 3                     |
715e41f4b71Sopenharmony_ci| Europe/Berlin                  | 2                     |
716e41f4b71Sopenharmony_ci| America/Guayaquil              | -5                    |
717e41f4b71Sopenharmony_ci| Europe/Madrid                  | 2                     |
718e41f4b71Sopenharmony_ci| Pacific/Pohnpei                | 11                    |
719e41f4b71Sopenharmony_ci| America/Godthab                | -2                    |
720e41f4b71Sopenharmony_ci| Asia/Jakarta                   | 7                     |
721e41f4b71Sopenharmony_ci| Pacific/Tarawa                 | 12                    |
722e41f4b71Sopenharmony_ci| Asia/Almaty                    | 6                     |
723e41f4b71Sopenharmony_ci| Pacific/Majuro                 | 12                    |
724e41f4b71Sopenharmony_ci| Asia/Ulaanbaatar               | 8                     |
725e41f4b71Sopenharmony_ci| America/Mexico_City            | -5                    |
726e41f4b71Sopenharmony_ci| Asia/Kuala_Lumpur              | 8                     |
727e41f4b71Sopenharmony_ci| Pacific/Auckland               | 12                    |
728e41f4b71Sopenharmony_ci| Pacific/Tahiti                 | -10                   |
729e41f4b71Sopenharmony_ci| Pacific/Port_Moresby           | 10                    |
730e41f4b71Sopenharmony_ci| Asia/Gaza                      | 3                     |
731e41f4b71Sopenharmony_ci| Europe/Lisbon                  | 1                     |
732e41f4b71Sopenharmony_ci| Europe/Moscow                  | 3                     |
733e41f4b71Sopenharmony_ci| Europe/Kiev                    | 3                     |
734e41f4b71Sopenharmony_ci| Pacific/Wake                   | 12                    |
735e41f4b71Sopenharmony_ci| America/New_York               | -4                    |
736e41f4b71Sopenharmony_ci| Asia/Tashkent                  | 5                     |
737