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