• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 # @ohos.systemTime (System Time and Time Zone)
2 
3 The **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.
4 
5 > **NOTE**
6 >
7 > - The APIs of this module are deprecated since API version 9. You are advised to use the APIs of the [@ohos.systemDateTime (System Time and Time Zone)](js-apis-system-date-time.md) module.
8 > - The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
9 
10 ## Modules to Import
11 
12 ```ts
13 import systemTime from '@ohos.systemTime';
14 ```
15 
16 ## systemTime.setTime
17 
18 setTime(time : number, callback : AsyncCallback<void>) : void
19 
20 Sets the system time. This API uses an asynchronous callback to return the result.
21 
22 **Required permissions**: ohos.permission.SET_TIME
23 
24 **System capability**: SystemCapability.MiscServices.Time
25 
26 **Parameters**
27 
28 | Name  | Type           | Mandatory| Description                                      |
29 | -------- | ----------- | ---- | ---------------- |
30 | time     | number                    | Yes  | Timestamp to set, in milliseconds.                        |
31 | callback | AsyncCallback<void> | Yes  | Callback used to return the result.|
32 
33 **Error codes**
34 
35 For details about the error codes, see [Time and Time Zone Service Error Codes](../errorcodes/errorcode-time.md).
36 
37 | ID| Error Message                                                    |
38 | -------- | ------------------------------------------------------------ |
39 | -1       | The parameter check failed or permission denied or system error. |
40 
41 **Example**
42 
43 ```ts
44 import { BusinessError } from '@ohos.base';
45 
46 // Set the system time to 2021-01-20 02:36:25.
47 let time = 1611081385000;
48 try {
49   systemTime.setTime(time, (error: BusinessError) => {
50     if (error) {
51       console.info(`Failed to setting time. message: ${error.message}, code: ${error.code}`);
52       return;
53     }
54     console.info(`Succeeded in setting time`);
55   });
56 } catch(e) {
57   let error = e as BusinessError;
58   console.info(`Failed to set time. message: ${error.message}, code: ${error.code}`);
59 }
60 ```
61 
62 ## systemTime.setTime
63 
64 setTime(time : number) : Promise<void>
65 
66 Sets the system time. This API uses a promise to return the result.
67 
68 **Required permissions**: ohos.permission.SET_TIME
69 
70 **System capability**: SystemCapability.MiscServices.Time
71 
72 **Parameters**
73 
74 | Name| Type  | Mandatory| Description              |
75 | ------ | ------ | ---- | ------------------ |
76 | time   | number | Yes  | Timestamp to set, in milliseconds.|
77 
78 **Return value**
79 
80 | Type               | Description                     |
81 | ------------------- | ------------------------- |
82 | Promise<void> | Promise that returns no value.|
83 
84 **Error codes**
85 
86 For details about the error codes, see [Time and Time Zone Service Error Codes](../errorcodes/errorcode-time.md).
87 
88 | ID| Error Message                                                    |
89 | -------- | ------------------------------------------------------------ |
90 | -1       | The parameter check failed or permission denied or system error. |
91 
92 **Example**
93 
94 ```ts
95 import { BusinessError } from '@ohos.base';
96 
97 // Set the system time to 2021-01-20 02:36:25.
98 let time = 1611081385000;
99 try {
100   systemTime.setTime(time).then(() => {
101     console.info(`Succeeded in setting time.`);
102   }).catch((error: BusinessError) => {
103     console.info(`Failed to setting time. message: ${error.message}, code: ${error.code}`);
104   });
105 } catch(e) {
106   let error = e as BusinessError;
107   console.info(`Failed to set time. message: ${error.message}, code: ${error.code}`);
108 }
109 ```
110 
111 ## systemTime.getCurrentTime<sup>8+</sup>
112 
113 getCurrentTime(isNano: boolean, callback: AsyncCallback&lt;number&gt;): void
114 
115 Obtains the time elapsed since the Unix epoch. This API uses an asynchronous callback to return the result.
116 
117 **System capability**: SystemCapability.MiscServices.Time
118 
119 **Parameters**
120 
121 | Name  | Type      | Mandatory| Description                            |
122 | -------- | -------------- | ---- | ------------------ |
123 | isNano   | boolean                     | Yes  | Whether the time to return is in nanoseconds.<br>- **true**: in nanoseconds.<br>- **false**: in milliseconds.|
124 | callback | AsyncCallback&lt;number&gt; | Yes  | Callback used to return the time elapsed since the Unix epoch.        |
125 
126 **Error codes**
127 
128 For details about the error codes, see [Time and Time Zone Service Error Codes](../errorcodes/errorcode-time.md).
129 
130 | ID| Error Message                                   |
131 | -------- | ------------------------------------------- |
132 | -1       | The parameter check failed or system error. |
133 
134 **Example**
135 
136 ```ts
137 import { BusinessError } from '@ohos.base';
138 
139 try {
140   systemTime.getCurrentTime(true, (error: BusinessError, time: number) => {
141     if (error) {
142       console.info(`Failed to getting currentTime. message: ${error.message}, code: ${error.code}`);
143       return;
144     }
145     console.info(`Succeeded in getting currentTime: ${time}`);
146   });
147 } catch(e) {
148   let error = e as BusinessError;
149   console.info(`Failed to get currentTime. message: ${error.message}, code: ${error.code}`);
150 }
151 ```
152 
153 ## systemTime.getCurrentTime<sup>8+</sup>
154 
155 getCurrentTime(callback: AsyncCallback&lt;number&gt;): void
156 
157 Obtains the time elapsed since the Unix epoch. This API uses an asynchronous callback to return the result.
158 
159 **System capability**: SystemCapability.MiscServices.Time
160 
161 **Parameters**
162 
163 | Name  | Type              | Mandatory| Description                           |
164 | -------- | ----------- | ---- | ---------------------------------- |
165 | callback | AsyncCallback&lt;number&gt; | Yes  | Callback used to return the time elapsed since the Unix epoch.        |
166 
167 **Error codes**
168 
169 For details about the error codes, see [Time and Time Zone Service Error Codes](../errorcodes/errorcode-time.md).
170 
171 | ID| Error Message                                   |
172 | -------- | ------------------------------------------- |
173 | -1       | The parameter check failed or system error. |
174 
175 **Example**
176 
177 ```ts
178 import { BusinessError } from '@ohos.base';
179 
180 try {
181   systemTime.getCurrentTime((error: BusinessError, time: number) => {
182     if (error) {
183       console.info(`Failed to getting currentTime. message: ${error.message}, code: ${error.code}`);
184       return;
185     }
186     console.info(`Succeeded in getting currentTime : ${time}`);
187   });
188 } catch(e) {
189   let error = e as BusinessError;
190   console.info(`Failed to get currentTime. message: ${error.message}, code: ${error.code}`);
191 }
192 ```
193 
194 ## systemTime.getCurrentTime<sup>8+</sup>
195 
196 getCurrentTime(isNano?: boolean): Promise&lt;number&gt;
197 
198 Obtains the time elapsed since the Unix epoch. This API uses a promise to return the result.
199 
200 **System capability**: SystemCapability.MiscServices.Time
201 
202 **Parameters**
203 
204 | Name| Type   | Mandatory| Description                    |
205 | ------ | ------- | ---- | ------------------------- |
206 | isNano | boolean | No  | Whether the time to return is in nanoseconds. The default value is **false**.<br>Default value: **false**<br>- **true**: in nanoseconds.<br>- **false**: in milliseconds.|
207 
208 **Return value**
209 
210 | Type       | Description                              |
211 | --------------------- | --------------------------- |
212 | Promise&lt;number&gt; | Promise used to return the time elapsed since the Unix epoch.|
213 
214 **Error codes**
215 
216 For details about the error codes, see [Time and Time Zone Service Error Codes](../errorcodes/errorcode-time.md).
217 
218 | ID| Error Message                                   |
219 | -------- | ------------------------------------------- |
220 | -1       | The parameter check failed or system error. |
221 
222 **Example**
223 
224 ```ts
225 import { BusinessError } from '@ohos.base';
226 
227 try {
228   systemTime.getCurrentTime().then((time: number) => {
229     console.info(`Succeeded in getting currentTime : ${time}`);
230   }).catch((error: BusinessError) => {
231     console.info(`Failed to getting currentTime. message: ${error.message}, code: ${error.code}`);
232   });
233 } catch(e) {
234   let error = e as BusinessError;
235   console.info(`Failed to get currentTime. message: ${error.message}, code: ${error.code}`);
236 }
237 ```
238 
239 ## systemTime.getRealActiveTime<sup>8+</sup>
240 
241 getRealActiveTime(isNano: boolean, callback: AsyncCallback&lt;number&gt;): void
242 
243 Obtains the time elapsed since system startup, excluding the deep sleep time. This API uses an asynchronous callback to return the result.
244 
245 **System capability**: SystemCapability.MiscServices.Time
246 
247 **Parameters**
248 
249 | Name  | Type                       | Mandatory| Description  |
250 | -------- | ---------- | ---- | -------------------------- |
251 | isNano   | boolean                     | Yes  | Whether the time to return is in nanoseconds.<br>- **true**: in nanoseconds.<br>- **false**: in milliseconds.|
252 | callback | AsyncCallback&lt;number&gt; | Yes  | Callback used to return the time.|
253 
254 **Error codes**
255 
256 For details about the error codes, see [Time and Time Zone Service Error Codes](../errorcodes/errorcode-time.md).
257 
258 | ID| Error Message                                   |
259 | -------- | ------------------------------------------- |
260 | -1       | The parameter check failed or system error. |
261 
262 **Example**
263 
264 ```ts
265 import { BusinessError } from '@ohos.base';
266 
267 try {
268   systemTime.getRealActiveTime(true, (error: BusinessError, time: number) => {
269     if (error) {
270       console.info(`Failed to getting real active time. message: ${error.message}, code: ${error.code}`);
271       return;
272     }
273     console.info(`Succeeded in getting real active time : ${time}`);
274   });
275 } catch(e) {
276   let error = e as BusinessError;
277   console.info(`Failed to get real active time. message: ${error.message}, code: ${error.code}`);
278 }
279 ```
280 
281 ## systemTime.getRealActiveTime<sup>8+</sup>
282 
283 getRealActiveTime(callback: AsyncCallback&lt;number&gt;): void
284 
285 Obtains the time elapsed since system startup, excluding the deep sleep time. This API uses an asynchronous callback to return the result.
286 
287 **System capability**: SystemCapability.MiscServices.Time
288 
289 **Parameters**
290 
291 | Name  | Type                       | Mandatory| Description   |
292 | -------- | -------------- | ---- | --------------------- |
293 | callback | AsyncCallback&lt;number&gt; | Yes  | Callback used to return the time.|
294 
295 **Error codes**
296 
297 For details about the error codes, see [Time and Time Zone Service Error Codes](../errorcodes/errorcode-time.md).
298 
299 | ID| Error Message                                   |
300 | -------- | ------------------------------------------- |
301 | -1       | The parameter check failed or system error. |
302 
303 **Example**
304 
305 ```ts
306 import { BusinessError } from '@ohos.base';
307 
308 try {
309   systemTime.getRealActiveTime((error: BusinessError, time: number) => {
310     if (error) {
311       console.info(`Failed to getting real active time. message: ${error.message}, code: ${error.code}`);
312       return;
313     }
314     console.info(`Succeeded in getting real active time : ${time}`);
315   });
316 } catch(e) {
317   let error = e as BusinessError;
318   console.info(`Failed to get real active time. message: ${error.message}, code: ${error.code}`);
319 }
320 ```
321 
322 ## systemTime.getRealActiveTime<sup>8+</sup>
323 
324 getRealActiveTime(isNano?: boolean): Promise&lt;number&gt;
325 
326 Obtains the time elapsed since system startup, excluding the deep sleep time. This API uses a promise to return the result.
327 
328 **System capability**: SystemCapability.MiscServices.Time
329 
330 **Parameters**
331 
332 | Name| Type   | Mandatory| Description                             |
333 | ------ | ------- | ---- | ----------------------------------- |
334 | isNano | boolean | No  | Whether the time to return is in nanoseconds. The default value is **false**.<br>Default value: **false**<br>- **true**: in nanoseconds.<br>- **false**: in milliseconds.|
335 
336 **Return value**
337 
338 | Type                 | Description        |
339 | -------------- | -------------------------------- |
340 | Promise&lt;number&gt; | Promise used to return the time elapsed since system startup, excluding the deep sleep time.|
341 
342 **Error codes**
343 
344 For details about the error codes, see [Time and Time Zone Service Error Codes](../errorcodes/errorcode-time.md).
345 
346 | ID| Error Message                                   |
347 | -------- | ------------------------------------------- |
348 | -1       | The parameter check failed or system error. |
349 
350 **Example**
351 
352 ```ts
353 import { BusinessError } from '@ohos.base';
354 
355 try {
356   systemTime.getRealActiveTime().then((time: number) => {
357     console.info(`Succeeded in getting real active time : ${time}`);
358   }).catch((error: BusinessError) => {
359     console.info(`Failed to getting real active time. message: ${error.message}, code: ${error.code}`);
360   });
361 } catch(e) {
362   let error = e as BusinessError;
363   console.info(`Failed to get real active time. message: ${error.message}, code: ${error.code}`);
364 }
365 ```
366 
367 ## systemTime.getRealTime<sup>8+</sup>
368 
369 getRealTime(isNano: boolean, callback: AsyncCallback&lt;number&gt;): void
370 
371 Obtains the time elapsed since system startup, including the deep sleep time. This API uses an asynchronous callback to return the result.
372 
373 **System capability**: SystemCapability.MiscServices.Time
374 
375 **Parameters**
376 
377 | Name  | Type                       | Mandatory| Description  |
378 | -------- | --------------- | ---- | ------------------------------- |
379 | isNano   | boolean                     | Yes  | Whether the time to return is in nanoseconds.<br>- **true**: in nanoseconds.<br>- **false**: in milliseconds.|
380 | callback | AsyncCallback&lt;number&gt; | Yes  | Callback used to return the time.  |
381 
382 **Error codes**
383 
384 For details about the error codes, see [Time and Time Zone Service Error Codes](../errorcodes/errorcode-time.md).
385 
386 | ID| Error Message                                   |
387 | -------- | ------------------------------------------- |
388 | -1       | The parameter check failed or system error. |
389 
390 **Example**
391 
392 ```ts
393 import { BusinessError } from '@ohos.base';
394 
395 try {
396   systemTime.getRealTime(true, (error: BusinessError, time: number) => {
397     if (error) {
398       console.info(`Failed to getting real time. message: ${error.message}, code: ${error.code}`);
399       return;
400     }
401     console.info(`Succeeded in getting real time : ${time}`);
402   });
403 } catch(e) {
404   let error = e as BusinessError;
405   console.info(`Failed to get real time. message: ${error.message}, code: ${error.code}`);
406 }
407 ```
408 
409 ## systemTime.getRealTime<sup>8+</sup>
410 
411 getRealTime(callback: AsyncCallback&lt;number&gt;): void
412 
413 Obtains the time elapsed since system startup, including the deep sleep time. This API uses an asynchronous callback to return the result.
414 
415 **System capability**: SystemCapability.MiscServices.Time
416 
417 **Parameters**
418 
419 | Name  | Type                       | Mandatory| Description     |
420 | -------- | --------- | ---- | --------------------------- |
421 | callback | AsyncCallback&lt;number&gt; | Yes  | Callback used to return the time.  |
422 
423 **Error codes**
424 
425 For details about the error codes, see [Time and Time Zone Service Error Codes](../errorcodes/errorcode-time.md).
426 
427 | ID| Error Message                                   |
428 | -------- | ------------------------------------------- |
429 | -1       | The parameter check failed or system error. |
430 
431 **Example**
432 
433 ```ts
434 import { BusinessError } from '@ohos.base';
435 
436 try {
437   systemTime.getRealTime((error: BusinessError, time: number) => {
438     if (error) {
439       console.info(`Failed to getting real time. message: ${error.message}, code: ${error.code}`);
440       return;
441     }
442     console.info(`Succeeded in getting real time : ${time}`);
443   });
444 } catch(e) {
445   let error = e as BusinessError;
446   console.info(`Failed to get real time. message: ${error.message}, code: ${error.code}`);
447 }
448 ```
449 
450 ## systemTime.getRealTime<sup>8+</sup>
451 
452 getRealTime(isNano?: boolean): Promise&lt;number&gt;
453 
454 Obtains the time elapsed since system startup, including the deep sleep time. This API uses a promise to return the result.
455 
456 **System capability**: SystemCapability.MiscServices.Time
457 
458 **Parameters**
459 
460 | Name| Type   | Mandatory| Description                              |
461 | ------ | ------- | ---- | ------------------------------- |
462 | isNano | boolean | No  | Whether the time to return is in nanoseconds. The default value is **false**.<br>Default value: **false**<br>- **true**: in nanoseconds.<br>- **false**: in milliseconds.|
463 
464 **Return value**
465 
466 | Type                 | Description      |
467 | --------------------- | ------------------------------- |
468 | Promise&lt;number&gt; | Promise used to return the time elapsed since system startup, including the deep sleep time.|
469 
470 **Error codes**
471 
472 For details about the error codes, see [Time and Time Zone Service Error Codes](../errorcodes/errorcode-time.md).
473 
474 | ID| Error Message                                   |
475 | -------- | ------------------------------------------- |
476 | -1       | The parameter check failed or system error. |
477 
478 **Example**
479 
480 ```ts
481 import { BusinessError } from '@ohos.base';
482 
483 try {
484   systemTime.getRealTime().then((time: number) => {
485     console.info(`Succeeded in getting real time : ${time}`);
486   }).catch((error: BusinessError) => {
487     console.info(`Failed to getting real time. message: ${error.message}, code: ${error.code}`);
488   });
489 } catch(e) {
490   let error = e as BusinessError;
491   console.info(`Failed to get real time. message: ${error.message}, code: ${error.code}`);
492 }
493 ```
494 
495 ## systemTime.setDate
496 
497 setDate(date: Date, callback: AsyncCallback&lt;void&gt;): void
498 
499 Sets the system date. This API uses an asynchronous callback to return the result.
500 
501 **Required permissions**: ohos.permission.SET_TIME
502 
503 **System capability**: SystemCapability.MiscServices.Time
504 
505 **Parameters**
506 
507 | Name  | Type                     | Mandatory| Description            |
508 | -------- | ------------- | ---- | --------------------- |
509 | date     | Date                      | Yes  | Target date to set.                                |
510 | callback | AsyncCallback&lt;void&gt; | Yes  | Callback used to return the result.|
511 
512 **Error codes**
513 
514 For details about the error codes, see [Time and Time Zone Service Error Codes](../errorcodes/errorcode-time.md).
515 
516 | ID| Error Message                                                    |
517 | -------- | ------------------------------------------------------------ |
518 | -1       | The parameter check failed or permission denied or system error. |
519 
520 **Example**
521 
522 ```ts
523 import { BusinessError } from '@ohos.base';
524 
525 let date = new Date();
526 try {
527   systemTime.setDate(date, (error: BusinessError) => {
528     if (error) {
529       console.info(`Failed to setting date. message: ${error.message}, code: ${error.code}`);
530       return;
531     }
532     console.info(`Succeeded in setting date.`);
533   });
534 } catch(e) {
535   let error = e as BusinessError;
536   console.info(`Failed to set date. message: ${error.message}, code: ${error.code}`);
537 }
538 ```
539 
540 ## systemTime.setDat
541 
542 setDate(date: Date): Promise&lt;void&gt;
543 
544 Sets the system date. This API uses a promise to return the result.
545 
546 **Required permissions**: ohos.permission.SET_TIME
547 
548 **System capability**: SystemCapability.MiscServices.Time
549 
550 **Parameters**
551 
552 | Name| Type| Mandatory| Description      |
553 | ------ | ---- | ---- | ---------- |
554 | date   | Date | Yes  | Target date to set.|
555 
556 **Return value**
557 
558 | Type               | Description                |
559 | ------------------- | -------------------- |
560 | Promise&lt;void&gt; | Promise that returns no value.|
561 
562 **Error codes**
563 
564 For details about the error codes, see [Time and Time Zone Service Error Codes](../errorcodes/errorcode-time.md).
565 
566 | ID| Error Message                                                    |
567 | -------- | ------------------------------------------------------------ |
568 | -1       | The parameter check failed or permission denied or system error. |
569 
570 **Example**
571 
572 ```ts
573 import { BusinessError } from '@ohos.base';
574 
575 let date = new Date();
576 try {
577   systemTime.setDate(date).then(() => {
578     console.info(`Succeeded in setting date.`);
579   }).catch((error: BusinessError) => {
580     console.info(`Failed to setting date. message: ${error.message}, code: ${error.code}`);
581   });
582 } catch(e) {
583   let error = e as BusinessError;
584   console.info(`Failed to set date. message: ${error.message}, code: ${error.code}`);
585 }
586 ```
587 
588 ## systemTime.getDate<sup>8+</sup>
589 
590 getDate(callback: AsyncCallback&lt;Date&gt;): void
591 
592 Obtains the current system date. This API uses an asynchronous callback to return the result.
593 
594 **System capability**: SystemCapability.MiscServices.Time
595 
596 **Parameters**
597 
598 | Name  | Type          | Mandatory| Description                  |
599 | -------- | -------------- | ---- | --------------------- |
600 | callback | AsyncCallback&lt;Date&gt; | Yes  | Callback used to return the current system date.|
601 
602 **Error codes**
603 
604 For details about the error codes, see [Time and Time Zone Service Error Codes](../errorcodes/errorcode-time.md).
605 
606 | ID| Error Message                                   |
607 | -------- | ------------------------------------------- |
608 | -1       | The parameter check failed or system error. |
609 
610 **Example**
611 
612 ```ts
613 import { BusinessError } from '@ohos.base';
614 
615 try {
616   systemTime.getDate((error: BusinessError, date: Date) => {
617     if (error) {
618       console.info(`Failed to get date. message: ${error.message}, code: ${error.code}`);
619       return;
620     }
621     console.info(`Succeeded in get date : ${date}`);;
622   });
623 } catch(e) {
624   let error = e as BusinessError;
625   console.info(`Failed to get date. message: ${error.message}, code: ${error.code}`);
626 }
627 ```
628 
629 ## systemTime.getDate<sup>8+</sup>
630 
631 getDate(): Promise&lt;Date&gt;
632 
633 Obtains the current system date. This API uses a promise to return the result.
634 
635 **System capability**: SystemCapability.MiscServices.Time
636 
637 **Return value**
638 
639 | Type               | Description                                     |
640 | ------------------- | ----------------------------------------- |
641 | Promise&lt;Date&gt; | Promise used to return the current system date.|
642 
643 **Error codes**
644 
645 For details about the error codes, see [Time and Time Zone Service Error Codes](../errorcodes/errorcode-time.md).
646 
647 | ID| Error Message                                   |
648 | -------- | ------------------------------------------- |
649 | -1       | The parameter check failed or system error. |
650 
651 **Example**
652 
653 ```ts
654 import { BusinessError } from '@ohos.base';
655 
656 try {
657   systemTime.getDate().then((date: Date) => {
658     console.info(`Succeeded in getting date : ${date}`);
659   }).catch((error: BusinessError) => {
660     console.info(`Failed to getting date. message: ${error.message}, code: ${error.code}`);
661   });
662 } catch(e) {
663   let error = e as BusinessError;
664   console.info(`Failed to get date. message: ${error.message}, code: ${error.code}`);
665 }
666 ```
667 
668 ## systemTime.setTimezone
669 
670 setTimezone(timezone: string, callback: AsyncCallback&lt;void&gt;): void
671 
672 Sets the system time zone. This API uses an asynchronous callback to return the result.
673 
674 **Required permissions**: ohos.permission.SET_TIME_ZONE
675 
676 **System capability**: SystemCapability.MiscServices.Time
677 
678 **Parameters**
679 
680 | Name  | Type             | Mandatory| Description                 |
681 | -------- | ------------- | ---- | -------------------------- |
682 | timezone | string                    | Yes  | System time zone to set. For details, see [Supported System Time Zones](#supported-system-time-zones).       |
683 | callback | AsyncCallback&lt;void&gt; | Yes  | Callback used to return the result.|
684 
685 **Error codes**
686 
687 For details about the error codes, see [Time and Time Zone Service Error Codes](../errorcodes/errorcode-time.md).
688 
689 | ID| Error Message                                                    |
690 | -------- | ------------------------------------------------------------ |
691 | -1       | The parameter check failed or permission denied or system error. |
692 
693 **Example**
694 
695 ```ts
696 import { BusinessError } from '@ohos.base';
697 
698 try {
699   systemTime.setTimezone('Asia/Shanghai', (error: BusinessError) => {
700     if (error) {
701       console.info(`Failed to setting timezone. message: ${error.message}, code: ${error.code}`);
702       return;
703     }
704     console.info(`Succeeded in setting timezone.`);
705   });
706 } catch(e) {
707   let error = e as BusinessError;
708   console.info(`Failed to set timezone. message: ${error.message}, code: ${error.code}`);
709 }
710 ```
711 
712 ## systemTime.setTimezon
713 
714 setTimezone(timezone: string): Promise&lt;void&gt;
715 
716 Sets the system time zone. This API uses a promise to return the result.
717 
718 **Required permissions**: ohos.permission.SET_TIME_ZONE
719 
720 **System capability**: SystemCapability.MiscServices.Time
721 
722 **Parameters**
723 
724 | Name  | Type  | Mandatory| Description      |
725 | -------- | ------ | ---- | ---------- |
726 | timezone | string | Yes  | System time zone to set. For details, see [Supported System Time Zones](#supported-system-time-zones).|
727 
728 **Return value**
729 
730 | Type               | Description                |
731 | ------------------- | -------------------- |
732 | Promise&lt;void&gt; | Promise that returns no value.|
733 
734 **Error codes**
735 
736 For details about the error codes, see [Time and Time Zone Service Error Codes](../errorcodes/errorcode-time.md).
737 
738 | ID| Error Message                                                    |
739 | -------- | ------------------------------------------------------------ |
740 | -1       | The parameter check failed or permission denied or system error. |
741 
742 **Example**
743 
744 ```ts
745 import { BusinessError } from '@ohos.base';
746 
747 try {
748   systemTime.setTimezone('Asia/Shanghai').then(() => {
749     console.info(`Succeeded in setting timezone.`);
750   }).catch((error: BusinessError) => {
751     console.info(`Failed to setting timezone. message: ${error.message}, code: ${error.code}`);
752   });
753 } catch(e) {
754   let error = e as BusinessError;
755   console.info(`Failed to set timezone. message: ${error.message}, code: ${error.code}`);
756 }
757 ```
758 
759 ## systemTime.getTimezone<sup>8+</sup>
760 
761 getTimezone(callback: AsyncCallback&lt;string&gt;): void
762 
763 Obtains the system time zone. This API uses an asynchronous callback to return the result.
764 
765 **System capability**: SystemCapability.MiscServices.Time
766 
767 **Parameters**
768 
769 | Name  | Type             | Mandatory| Description                |
770 | -------- | --------- | ---- | ------------------------ |
771 | 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).|
772 
773 **Error codes**
774 
775 For details about the error codes, see [Time and Time Zone Service Error Codes](../errorcodes/errorcode-time.md).
776 
777 | ID| Error Message                                   |
778 | -------- | ------------------------------------------- |
779 | -1       | The parameter check failed or system error. |
780 
781 **Example**
782 
783 ```ts
784 import { BusinessError } from '@ohos.base';
785 
786 try {
787   systemTime.getTimezone((error: BusinessError, data: string) => {
788     if (error) {
789       console.info(`Failed to get timezone. message: ${error.message}, code: ${error.code}`);
790       return;
791     }
792     console.info(`Succeeded in get timezone : ${data}`);;
793   });
794 } catch(e) {
795   let error = e as BusinessError;
796   console.info(`Failed to get timezone. message: ${error.message}, code: ${error.code}`);
797 }
798 ```
799 
800 ## systemTime.getTimezone<sup>8+</sup>
801 
802 getTimezone(): Promise&lt;string&gt;
803 
804 Obtains the system time zone. This API uses a promise to return the result.
805 
806 **System capability**: SystemCapability.MiscServices.Time
807 
808 **Return value**
809 
810 | Type                 | Description                                 |
811 | --------------------- | ------------------------------------- |
812 | Promise&lt;string&gt; | Promise used to return the system time zone. For details, see [Supported System Time Zones](#supported-system-time-zones).|
813 
814 **Error codes**
815 
816 For details about the error codes, see [Time and Time Zone Service Error Codes](../errorcodes/errorcode-time.md).
817 
818 | ID| Error Message                                   |
819 | -------- | ------------------------------------------- |
820 | -1       | The parameter check failed or system error. |
821 
822 **Example**
823 
824 ```ts
825 import { BusinessError } from '@ohos.base';
826 
827 try {
828   systemTime.getTimezone().then((data: string) => {
829     console.info(`Succeeded in getting timezone: ${data}`);
830   }).catch((error: BusinessError) => {
831     console.info(`Failed to getting timezone. message: ${error.message}, code: ${error.code}`);
832   });
833 } catch(e) {
834   let error = e as BusinessError;
835   console.info(`Failed to get timezone. message: ${error.message}, code: ${error.code}`);
836 }
837 ```
838 
839 ## Supported System Time Zones
840 
841 The following table lists the supported system time zones and the respective offset (unit: h) between each time zone and time zone 0.
842 
843 | Time Zone                          | Offset        |
844 | ------------------------------ | --------------------- |
845 | Antarctica/McMurdo             | 12                    |
846 | America/Argentina/Buenos_Aires | -3                    |
847 | Australia/Sydney               | 10                    |
848 | America/Noronha                | -2                    |
849 | America/St_Johns               | -3                    |
850 | Africa/Kinshasa                | 1                     |
851 | America/Santiago               | -3                    |
852 | Asia/Shanghai                  | 8                     |
853 | Asia/Nicosia                   | 3                     |
854 | Europe/Berlin                  | 2                     |
855 | America/Guayaquil              | -5                    |
856 | Europe/Madrid                  | 2                     |
857 | Pacific/Pohnpei                | 11                    |
858 | America/Godthab                | -2                    |
859 | Asia/Jakarta                   | 7                     |
860 | Pacific/Tarawa                 | 12                    |
861 | Asia/Almaty                    | 6                     |
862 | Pacific/Majuro                 | 12                    |
863 | Asia/Ulaanbaatar               | 8                     |
864 | America/Mexico_City            | -5                    |
865 | Asia/Kuala_Lumpur              | 8                     |
866 | Pacific/Auckland               | 12                    |
867 | Pacific/Tahiti                 | -10                   |
868 | Pacific/Port_Moresby           | 10                    |
869 | Asia/Gaza                      | 3                     |
870 | Europe/Lisbon                  | 1                     |
871 | Europe/Moscow                  | 3                     |
872 | Europe/Kiev                    | 3                     |
873 | Pacific/Wake                   | 12                    |
874 | America/New_York               | -4                    |
875 | Asia/Tashkent                  | 5                     |
876