未验证 提交 138a5b5d 编写于 作者: O openharmony_ci 提交者: Gitee

!13847 翻译完成 13519

Merge pull request !13847 from ester.zhou/TR-13519
# @ohos.systemTime # @ohos.systemTime (System Time and Time Zone)
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. 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.
...@@ -29,21 +29,29 @@ Sets the system time. This API uses an asynchronous callback to return the resul ...@@ -29,21 +29,29 @@ Sets the system time. This API uses an asynchronous callback to return the resul
| time | number | Yes | Timestamp to set, in milliseconds. | | time | number | Yes | Timestamp to set, in milliseconds. |
| callback | AsyncCallback<void> | Yes | Callback used to return the result.| | callback | AsyncCallback<void> | Yes | Callback used to return the result.|
**Error codes**
For details about the error codes, see [Time and Time Zone Service Error Codes](../errorcodes/errorcode-time.md).
| ID| Error Message |
| -------- | ------------------------------------------------------------ |
| -1 | The parameter check failed or permission denied or system error. |
**Example** **Example**
```js ```js
// Set the system time to 2021-01-20 02:36:25. // Set the system time to 2021-01-20 02:36:25.
let time = 1611081385000; let time = 1611081385000;
try { try {
systemTime.setTime(time, (error) => { systemTime.setTime(time, (error) => {
if (error) { if (error) {
console.info(`Failed to setting time. message:${error.message}, code:${error.code}`); console.info(`Failed to setting time. message: ${error.message}, code: ${error.code}`);
return; return;
} }
console.info(`Succeeded in setting time`); }console.info(`Succeeded in setting time`);
}); });
} catch(e) { } catch(e) {
console.info(`Failed to set time. message:${e.message}, code:${e.code}`); console.info(`Failed to set time. message: ${e.message}, code: ${e.code}`);
} }
``` ```
...@@ -69,19 +77,27 @@ Sets the system time. This API uses a promise to return the result. ...@@ -69,19 +77,27 @@ Sets the system time. This API uses a promise to return the result.
| ------------------- | ------------------------- | | ------------------- | ------------------------- |
| Promise<void> | Promise that returns no value.| | Promise<void> | Promise that returns no value.|
**Error codes**
For details about the error codes, see [Time and Time Zone Service Error Codes](../errorcodes/errorcode-time.md).
| ID| Error Message |
| -------- | ------------------------------------------------------------ |
| -1 | The parameter check failed or permission denied or system error. |
**Example** **Example**
```js ```js
// Set the system time to 2021-01-20 02:36:25. // Set the system time to 2021-01-20 02:36:25.
let time = 1611081385000; let time = 1611081385000;
try { try {
systemTime.setTime(time).then(() => { systemTime.setTime(time).then(() => {
console.info(`Succeeded in setting time.`); console.info(`Succeeded in setting time.`);
}).catch((error) => { }).catch((error) => {
console.info(`Failed to setting time. message:${error.message}, code:${error.code}`); console.info(`Failed to setting time. message: ${error.message}, code: ${error.code}`);
}); });
} catch(e) { } catch(e) {
console.info(`Failed to set time. message:${e.message}, code:${e.code}`); console.info(`Failed to set time. message: ${e.message}, code: ${e.code}`);
} }
``` ```
...@@ -101,22 +117,30 @@ Obtains the time elapsed since the Unix epoch. This API uses an asynchronous cal ...@@ -101,22 +117,30 @@ Obtains the time elapsed since the Unix epoch. This API uses an asynchronous cal
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | -------------- | ---- | ------------------ | | -------- | -------------- | ---- | ------------------ |
| isNano | boolean | Yes | Whether the time to return is in nanoseconds.<br>- **true**: in nanoseconds (ns).<br>- **false**: in milliseconds (ms).| | isNano | boolean | Yes | Whether the time to return is in nanoseconds.<br>- **true**: in nanoseconds.<br>- **false**: in milliseconds.|
| callback | AsyncCallback&lt;number&gt; | Yes | Callback used to return the time elapsed since the Unix epoch. | | callback | AsyncCallback&lt;number&gt; | Yes | Callback used to return the time elapsed since the Unix epoch. |
**Error codes**
For details about the error codes, see [Time and Time Zone Service Error Codes](../errorcodes/errorcode-time.md).
| ID| Error Message |
| -------- | ------------------------------------------- |
| -1 | The parameter check failed or system error. |
**Example** **Example**
```js ```js
try { try {
systemTime.getCurrentTime(true, (error, time) => { systemTime.getCurrentTime(true, (error, time) => {
if (error) { if (error) {
console.info(`Failed to getting currentTime. message:${error.message}, code:${error.code}`); console.info(`Failed to getting currentTime. message: ${error.message}, code: ${error.code}`);
return; return;
} }
console.info(`Succeeded in getting currentTime : ${time}`); console.info(`Succeeded in getting currentTime: ${time}`);
}); });
} catch(e) { } catch(e) {
console.info(`Failed to get currentTime. message:${e.message}, code:${e.code}`); console.info(`Failed to get currentTime. message: ${e.message}, code: ${e.code}`);
} }
``` ```
...@@ -138,19 +162,27 @@ Obtains the time elapsed since the Unix epoch. This API uses an asynchronous cal ...@@ -138,19 +162,27 @@ Obtains the time elapsed since the Unix epoch. This API uses an asynchronous cal
| -------- | ----------- | ---- | ---------------------------------- | | -------- | ----------- | ---- | ---------------------------------- |
| callback | AsyncCallback&lt;number&gt; | Yes | Callback used to return the time elapsed since the Unix epoch. | | callback | AsyncCallback&lt;number&gt; | Yes | Callback used to return the time elapsed since the Unix epoch. |
**Error codes**
For details about the error codes, see [Time and Time Zone Service Error Codes](../errorcodes/errorcode-time.md).
| ID| Error Message |
| -------- | ------------------------------------------- |
| -1 | The parameter check failed or system error. |
**Example** **Example**
```js ```js
try { try {
systemTime.getCurrentTime((error, time) => { systemTime.getCurrentTime((error, time) => {
if (error) { if (error) {
console.info(`Failed to getting currentTime. message:${error.message}, code:${error.code}`); console.info(`Failed to getting currentTime. message: ${error.message}, code: ${error.code}`);
return; return;
} }
console.info(`Succeeded in getting currentTime : ${time}`); console.info(`Succeeded in getting currentTime : ${time}`);
}); });
} catch(e) { } catch(e) {
console.info(`Failed to get currentTime. message:${e.message}, code:${e.code}`); console.info(`Failed to get currentTime. message: ${e.message}, code: ${e.code}`);
} }
``` ```
...@@ -170,7 +202,7 @@ Obtains the time elapsed since the Unix epoch. This API uses a promise to return ...@@ -170,7 +202,7 @@ Obtains the time elapsed since the Unix epoch. This API uses a promise to return
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------- | ---- | ------------------------- | | ------ | ------- | ---- | ------------------------- |
| isNano | boolean | No | Whether the time to return is in nanoseconds.<br>- **true**: in nanoseconds (ns).<br>- **false**: in milliseconds (ms).| | isNano | boolean | No | Whether the time to return is in nanoseconds.<br>- **true**: in nanoseconds.<br>- **false**: in milliseconds.|
**Return value** **Return value**
...@@ -178,17 +210,25 @@ Obtains the time elapsed since the Unix epoch. This API uses a promise to return ...@@ -178,17 +210,25 @@ Obtains the time elapsed since the Unix epoch. This API uses a promise to return
| --------------------- | --------------------------- | | --------------------- | --------------------------- |
| Promise&lt;number&gt; | Promise used to return the time elapsed since the Unix epoch.| | Promise&lt;number&gt; | Promise used to return the time elapsed since the Unix epoch.|
**Error codes**
For details about the error codes, see [Time and Time Zone Service Error Codes](../errorcodes/errorcode-time.md).
| ID| Error Message |
| -------- | ------------------------------------------- |
| -1 | The parameter check failed or system error. |
**Example** **Example**
```js ```js
try { try {
systemTime.getCurrentTime().then((time) => { systemTime.getCurrentTime().then((time) => {
console.info(`Succeeded in getting currentTime : ${time}`); console.info(`Succeeded in getting currentTime : ${time}`);
}).catch((error) => { }).catch((error) => {
console.info(`Failed to getting currentTime. message:${error.message}, code:${error.code}`); console.info(`Failed to getting currentTime. message: ${error.message}, code: ${error.code}`);
}); });
} catch(e) { } catch(e) {
console.info(`Failed to get currentTime. message:${e.message}, code:${e.code}`); console.info(`Failed to get currentTime. message: ${e.message}, code: ${e.code}`);
} }
``` ```
...@@ -208,22 +248,30 @@ Obtains the time elapsed since system startup, excluding the deep sleep time. Th ...@@ -208,22 +248,30 @@ Obtains the time elapsed since system startup, excluding the deep sleep time. Th
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ---------- | ---- | -------------------------- | | -------- | ---------- | ---- | -------------------------- |
| isNano | boolean | Yes | Whether the time to return is in nanoseconds.<br>- **true**: in nanoseconds (ns).<br>- **false**: in milliseconds (ms).| | isNano | boolean | Yes | Whether the time to return is in nanoseconds.<br>- **true**: in nanoseconds.<br>- **false**: in milliseconds.|
| callback | AsyncCallback&lt;number&gt; | Yes | Callback used to return the time.| | callback | AsyncCallback&lt;number&gt; | Yes | Callback used to return the time.|
**Error codes**
For details about the error codes, see [Time and Time Zone Service Error Codes](../errorcodes/errorcode-time.md).
| ID| Error Message |
| -------- | ------------------------------------------- |
| -1 | The parameter check failed or system error. |
**Example** **Example**
```js ```js
try { try {
systemTime.getRealActiveTime(true, (error, time) => { systemTime.getRealActiveTime(true, (error, time) => {
if (error) { if (error) {
console.info(`Failed to getting real active time. message:${error.message}, code:${error.code}`); console.info(`Failed to getting real active time. message: ${error.message}, code: ${error.code}`);
return; return;
} }
console.info(`Succeeded in getting real active time : ${time}`); console.info(`Succeeded in getting real active time : ${time}`);
}); });
} catch(e) { } catch(e) {
console.info(`Failed to get real active time. message:${e.message}, code:${e.code}`); console.info(`Failed to get real active time. message: ${e.message}, code: ${e.code}`);
} }
``` ```
...@@ -245,19 +293,27 @@ Obtains the time elapsed since system startup, excluding the deep sleep time. Th ...@@ -245,19 +293,27 @@ Obtains the time elapsed since system startup, excluding the deep sleep time. Th
| -------- | -------------- | ---- | --------------------- | | -------- | -------------- | ---- | --------------------- |
| callback | AsyncCallback&lt;number&gt; | Yes | Callback used to return the time.| | callback | AsyncCallback&lt;number&gt; | Yes | Callback used to return the time.|
**Error codes**
For details about the error codes, see [Time and Time Zone Service Error Codes](../errorcodes/errorcode-time.md).
| ID| Error Message |
| -------- | ------------------------------------------- |
| -1 | The parameter check failed or system error. |
**Example** **Example**
```js ```js
try { try {
systemTime.getRealActiveTime((error, time) => { systemTime.getRealActiveTime((error, time) => {
if (error) { if (error) {
console.info(`Failed to getting real active time. message:${error.message}, code:${error.code}`); console.info(`Failed to getting real active time. message: ${error.message}, code: ${error.code}`);
return; return;
} }
console.info(`Succeeded in getting real active time : ${time}`); console.info(`Succeeded in getting real active time : ${time}`);
}); });
} catch(e) { } catch(e) {
console.info(`Failed to get real active time. message:${e.message}, code:${e.code}`); console.info(`Failed to get real active time. message: ${e.message}, code: ${e.code}`);
} }
``` ```
...@@ -277,7 +333,7 @@ Obtains the time elapsed since system startup, excluding the deep sleep time. Th ...@@ -277,7 +333,7 @@ Obtains the time elapsed since system startup, excluding the deep sleep time. Th
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------- | ---- | ----------------------------------- | | ------ | ------- | ---- | ----------------------------------- |
| isNano | boolean | No | Whether the time to return is in nanoseconds.<br>- **true**: in nanoseconds (ns).<br>- **false**: in milliseconds (ms).| | isNano | boolean | No | Whether the time to return is in nanoseconds.<br>- **true**: in nanoseconds.<br>- **false**: in milliseconds.|
**Return value** **Return value**
...@@ -285,17 +341,25 @@ Obtains the time elapsed since system startup, excluding the deep sleep time. Th ...@@ -285,17 +341,25 @@ Obtains the time elapsed since system startup, excluding the deep sleep time. Th
| -------------- | -------------------------------- | | -------------- | -------------------------------- |
| Promise&lt;number&gt; | Promise used to return the time elapsed since system startup, excluding the deep sleep time.| | Promise&lt;number&gt; | Promise used to return the time elapsed since system startup, excluding the deep sleep time.|
**Error codes**
For details about the error codes, see [Time and Time Zone Service Error Codes](../errorcodes/errorcode-time.md).
| ID| Error Message |
| -------- | ------------------------------------------- |
| -1 | The parameter check failed or system error. |
**Example** **Example**
```js ```js
try { try {
systemTime.getRealActiveTime().then((time) => { systemTime.getRealActiveTime().then((time) => {
console.info(`Succeeded in getting real active time : ${time}`); console.info(`Succeeded in getting real active time : ${time}`);
}).catch((error) => { }).catch((error) => {
console.info(`Failed to getting real active time. message:${error.message}, code:${error.code}`); console.info(`Failed to getting real active time. message: ${error.message}, code: ${error.code}`);
}); });
} catch(e) { } catch(e) {
console.info(`Failed to get real active time. message:${e.message}, code:${e.code}`); console.info(`Failed to get real active time. message: ${e.message}, code: ${e.code}`);
} }
``` ```
...@@ -315,22 +379,30 @@ Obtains the time elapsed since system startup, including the deep sleep time. Th ...@@ -315,22 +379,30 @@ Obtains the time elapsed since system startup, including the deep sleep time. Th
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | --------------- | ---- | ------------------------------- | | -------- | --------------- | ---- | ------------------------------- |
| isNano | boolean | Yes | Whether the time to return is in nanoseconds.<br>- **true**: in nanoseconds (ns).<br>- **false**: in milliseconds (ms).| | isNano | boolean | Yes | Whether the time to return is in nanoseconds.<br>- **true**: in nanoseconds.<br>- **false**: in milliseconds.|
| callback | AsyncCallback&lt;number&gt; | Yes | Callback used to return the time. | | callback | AsyncCallback&lt;number&gt; | Yes | Callback used to return the time. |
**Error codes**
For details about the error codes, see [Time and Time Zone Service Error Codes](../errorcodes/errorcode-time.md).
| ID| Error Message |
| -------- | ------------------------------------------- |
| -1 | The parameter check failed or system error. |
**Example** **Example**
```js ```js
try { try {
systemTime.getRealTime(true, (error, time) => { systemTime.getRealTime(true, (error, time) => {
if (error) { if (error) {
console.info(`Failed to getting real time. message:${error.message}, code:${error.code}`); console.info(`Failed to getting real time. message: ${error.message}, code: ${error.code}`);
return; return;
} }
console.info(`Succeeded in getting real time : ${time}`); console.info(`Succeeded in getting real time : ${time}`);
}); });
} catch(e) { } catch(e) {
console.info(`Failed to get real time. message:${e.message}, code:${e.code}`); console.info(`Failed to get real time. message: ${e.message}, code: ${e.code}`);
} }
``` ```
...@@ -352,19 +424,27 @@ Obtains the time elapsed since system startup, including the deep sleep time. Th ...@@ -352,19 +424,27 @@ Obtains the time elapsed since system startup, including the deep sleep time. Th
| -------- | --------- | ---- | --------------------------- | | -------- | --------- | ---- | --------------------------- |
| callback | AsyncCallback&lt;number&gt; | Yes | Callback used to return the time. | | callback | AsyncCallback&lt;number&gt; | Yes | Callback used to return the time. |
**Error codes**
For details about the error codes, see [Time and Time Zone Service Error Codes](../errorcodes/errorcode-time.md).
| ID| Error Message |
| -------- | ------------------------------------------- |
| -1 | The parameter check failed or system error. |
**Example** **Example**
```js ```js
try { try {
systemTime.getRealTime((error, time) => { systemTime.getRealTime((error, time) => {
if (error) { if (error) {
console.info(`Failed to getting real time. message:${error.message}, code:${error.code}`); console.info(`Failed to getting real time. message: ${error.message}, code: ${error.code}`);
return; return;
} }
console.info(`Succeeded in getting real time : ${time}`); console.info(`Succeeded in getting real time : ${time}`);
}); });
} catch(e) { } catch(e) {
console.info(`Failed to get real time. message:${e.message}, code:${e.code}`); console.info(`Failed to get real time. message: ${e.message}, code: ${e.code}`);
} }
``` ```
...@@ -384,7 +464,7 @@ Obtains the time elapsed since system startup, including the deep sleep time. Th ...@@ -384,7 +464,7 @@ Obtains the time elapsed since system startup, including the deep sleep time. Th
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------- | ---- | ------------------------------- | | ------ | ------- | ---- | ------------------------------- |
| isNano | boolean | No | Whether the time to return is in nanoseconds.<br>- **true**: in nanoseconds (ns).<br>- **false**: in milliseconds (ms).| | isNano | boolean | No | Whether the time to return is in nanoseconds.<br>- **true**: in nanoseconds.<br>- **false**: in milliseconds.|
**Return value** **Return value**
...@@ -392,17 +472,25 @@ Obtains the time elapsed since system startup, including the deep sleep time. Th ...@@ -392,17 +472,25 @@ Obtains the time elapsed since system startup, including the deep sleep time. Th
| --------------------- | ------------------------------- | | --------------------- | ------------------------------- |
| Promise&lt;number&gt; | Promise used to return the time elapsed since system startup, including the deep sleep time.| | Promise&lt;number&gt; | Promise used to return the time elapsed since system startup, including the deep sleep time.|
**Error codes**
For details about the error codes, see [Time and Time Zone Service Error Codes](../errorcodes/errorcode-time.md).
| ID| Error Message |
| -------- | ------------------------------------------- |
| -1 | The parameter check failed or system error. |
**Example** **Example**
```js ```js
try { try {
systemTime.getRealTime().then((time) => { systemTime.getRealTime().then((time) => {
console.info(`Succeeded in getting real time : ${time}`); console.info(`Succeeded in getting real time : ${time}`);
}).catch((error) => { }).catch((error) => {
console.info(`Failed to getting real time. message:${error.message}, code:${error.code}`); console.info(`Failed to getting real time. message: ${error.message}, code: ${error.code}`);
}); });
} catch(e) { } catch(e) {
console.info(`Failed to get real time. message:${e.message}, code:${e.code}`); console.info(`Failed to get real time. message: ${e.message}, code: ${e.code}`);
} }
``` ```
...@@ -423,20 +511,28 @@ Sets the system date. This API uses an asynchronous callback to return the resul ...@@ -423,20 +511,28 @@ Sets the system date. This API uses an asynchronous callback to return the resul
| date | Date | Yes | Target date to set. | | date | Date | Yes | Target date to set. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result.| | callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result.|
**Error codes**
For details about the error codes, see [Time and Time Zone Service Error Codes](../errorcodes/errorcode-time.md).
| ID| Error Message |
| -------- | ------------------------------------------------------------ |
| -1 | The parameter check failed or permission denied or system error. |
**Example** **Example**
```js ```js
let date = new Date(); let date = new Date();
try { try {
systemTime.setDate(date, (error) => { systemTime.setDate(date, (error) => {
if (error) { if (error) {
console.info(`Failed to setting date. message:${error.message}, code:${error.code}`); console.info(`Failed to setting date. message: ${error.message}, code: ${error.code}`);
return; return;
} }
console.info(`Succeeded in setting date.`); console.info(`Succeeded in setting date.`);
}); });
} catch(e) { } catch(e) {
console.info(`Failed to set date. message:${e.message}, code:${e.code}`); console.info(`Failed to set date. message: ${e.message}, code: ${e.code}`);
} }
``` ```
...@@ -462,18 +558,26 @@ Sets the system date. This API uses a promise to return the result. ...@@ -462,18 +558,26 @@ Sets the system date. This API uses a promise to return the result.
| ------------------- | -------------------- | | ------------------- | -------------------- |
| Promise&lt;void&gt; | Promise that returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Error codes**
For details about the error codes, see [Time and Time Zone Service Error Codes](../errorcodes/errorcode-time.md).
| ID| Error Message |
| -------- | ------------------------------------------------------------ |
| -1 | The parameter check failed or permission denied or system error. |
**Example** **Example**
```js ```js
let date = new Date(); let date = new Date();
try { try {
systemTime.setDate(date).then(() => { systemTime.setDate(date).then(() => {
console.info(`Succeeded in setting date.`); console.info(`Succeeded in setting date.`);
}).catch((error) => { }).catch((error) => {
console.info(`Failed to setting date. message:${error.message}, code:${error.code}`); console.info(`Failed to setting date. message: ${error.message}, code: ${error.code}`);
}); });
} catch(e) { } catch(e) {
console.info(`Failed to set date. message:${e.message}, code:${e.code}`); console.info(`Failed to set date. message: ${e.message}, code: ${e.code}`);
} }
``` ```
...@@ -495,19 +599,27 @@ Obtains the current system date. This API uses an asynchronous callback to retur ...@@ -495,19 +599,27 @@ Obtains the current system date. This API uses an asynchronous callback to retur
| -------- | -------------- | ---- | --------------------- | | -------- | -------------- | ---- | --------------------- |
| callback | AsyncCallback&lt;Date&gt; | Yes | Callback used to return the current system date.| | callback | AsyncCallback&lt;Date&gt; | Yes | Callback used to return the current system date.|
**Error codes**
For details about the error codes, see [Time and Time Zone Service Error Codes](../errorcodes/errorcode-time.md).
| ID| Error Message |
| -------- | ------------------------------------------- |
| -1 | The parameter check failed or system error. |
**Example** **Example**
```js ```js
try { try {
systemTime.getDate((error, date) => { systemTime.getDate((error, date) => {
if (error) { if (error) {
console.info(`Failed to get date. message:${error.message}, code:${error.code}`); console.info(`Failed to get date. message: ${error.message}, code: ${error.code}`);
return; return;
} }
console.info(`Succeeded in get date : ${date}`);; console.info(`Succeeded in get date : ${date}`);;
}); });
} catch(e) { } catch(e) {
console.info(`Failed to get date. message:${e.message}, code:${e.code}`); console.info(`Failed to get date. message: ${e.message}, code: ${e.code}`);
} }
``` ```
...@@ -529,17 +641,25 @@ Obtains the current system date. This API uses a promise to return the result. ...@@ -529,17 +641,25 @@ Obtains the current system date. This API uses a promise to return the result.
| ------------------- | ----------------------------------------- | | ------------------- | ----------------------------------------- |
| Promise&lt;Date&gt; | Promise used to return the current system date.| | Promise&lt;Date&gt; | Promise used to return the current system date.|
**Error codes**
For details about the error codes, see [Time and Time Zone Service Error Codes](../errorcodes/errorcode-time.md).
| ID| Error Message |
| -------- | ------------------------------------------- |
| -1 | The parameter check failed or system error. |
**Example** **Example**
```js ```js
try { try {
systemTime.getDate().then((date) => { systemTime.getDate().then((date) => {
console.info(`Succeeded in getting date : ${date}`); console.info(`Succeeded in getting date : ${date}`);
}).catch((error) => { }).catch((error) => {
console.info(`Failed to getting date. message:${error.message}, code:${error.code}`); console.info(`Failed to getting date. message: ${error.message}, code: ${error.code}`);
}); });
} catch(e) { } catch(e) {
console.info(`Failed to get date. message:${e.message}, code:${e.code}`); console.info(`Failed to get date. message: ${e.message}, code: ${e.code}`);
} }
``` ```
...@@ -560,19 +680,27 @@ Sets the system time zone. This API uses an asynchronous callback to return the ...@@ -560,19 +680,27 @@ Sets the system time zone. This API uses an asynchronous callback to return the
| timezone | string | Yes | System time zone to set. For details, see [Supported System Time Zones](#supported-system-time-zones). | | timezone | string | Yes | System time zone to set. For details, see [Supported System Time Zones](#supported-system-time-zones). |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result.| | callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result.|
**Error codes**
For details about the error codes, see [Time and Time Zone Service Error Codes](../errorcodes/errorcode-time.md).
| ID| Error Message |
| -------- | ------------------------------------------------------------ |
| -1 | The parameter check failed or permission denied or system error. |
**Example** **Example**
```js ```js
try { try {
systemTime.setTimezone('Asia/Shanghai', (error) => { systemTime.setTimezone('Asia/Shanghai', (error) => {
if (error) { if (error) {
console.info(`Failed to setting timezone. message:${error.message}, code:${error.code}`); console.info(`Failed to setting timezone. message: ${error.message}, code: ${error.code}`);
return; return;
} }
console.info(`Succeeded in setting timezone.`); console.info(`Succeeded in setting timezone.`);
}); });
} catch(e) { } catch(e) {
console.info(`Failed to set timezone. message:${e.message}, code:${e.code}`); console.info(`Failed to set timezone. message: ${e.message}, code: ${e.code}`);
} }
``` ```
...@@ -598,17 +726,25 @@ Sets the system time zone. This API uses a promise to return the result. ...@@ -598,17 +726,25 @@ Sets the system time zone. This API uses a promise to return the result.
| ------------------- | -------------------- | | ------------------- | -------------------- |
| Promise&lt;void&gt; | Promise that returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Error codes**
For details about the error codes, see [Time and Time Zone Service Error Codes](../errorcodes/errorcode-time.md).
| ID| Error Message |
| -------- | ------------------------------------------------------------ |
| -1 | The parameter check failed or permission denied or system error. |
**Example** **Example**
```js ```js
try { try {
systemTime.setTimezone('Asia/Shanghai').then(() => { systemTime.setTimezone('Asia/Shanghai').then(() => {
console.info(`Succeeded in setting timezone.`); console.info(`Succeeded in setting timezone.`);
}).catch((error) => { }).catch((error) => {
console.info(`Failed to setting timezone. message:${error.message}, code:${error.code}`); console.info(`Failed to setting timezone. message: ${error.message}, code: ${error.code}`);
}); });
} catch(e) { } catch(e) {
console.info(`Failed to set timezone. message:${e.message}, code:${e.code}`); console.info(`Failed to set timezone. message: ${e.message}, code: ${e.code}`);
} }
``` ```
...@@ -630,19 +766,27 @@ Obtains the system time zone. This API uses an asynchronous callback to return t ...@@ -630,19 +766,27 @@ Obtains the system time zone. This API uses an asynchronous callback to return t
| -------- | --------- | ---- | ------------------------ | | -------- | --------- | ---- | ------------------------ |
| 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).| | 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).|
**Error codes**
For details about the error codes, see [Time and Time Zone Service Error Codes](../errorcodes/errorcode-time.md).
| ID| Error Message |
| -------- | ------------------------------------------- |
| -1 | The parameter check failed or system error. |
**Example** **Example**
```js ```js
try { try {
systemTime.getTimezone((error, data) => { systemTime.getTimezone((error, data) => {
if (error) { if (error) {
console.info(`Failed to get timezone. message:${error.message}, code:${error.code}`); console.info(`Failed to get timezone. message: ${error.message}, code: ${error.code}`);
return; return;
} }
console.info(`Succeeded in get timezone : ${data}`);; console.info(`Succeeded in get timezone : ${data}`);;
}); });
} catch(e) { } catch(e) {
console.info(`Failed to get timezone. message:${e.message}, code:${e.code}`); console.info(`Failed to get timezone. message: ${e.message}, code: ${e.code}`);
} }
``` ```
...@@ -664,17 +808,25 @@ Obtains the system time zone. This API uses a promise to return the result. ...@@ -664,17 +808,25 @@ Obtains the system time zone. This API uses a promise to return the result.
| --------------------- | ------------------------------------- | | --------------------- | ------------------------------------- |
| Promise&lt;string&gt; | Promise used to return the system time zone. For details, see [Supported System Time Zones](#supported-system-time-zones).| | Promise&lt;string&gt; | Promise used to return the system time zone. For details, see [Supported System Time Zones](#supported-system-time-zones).|
**Error codes**
For details about the error codes, see [Time and Time Zone Service Error Codes](../errorcodes/errorcode-time.md).
| ID| Error Message |
| -------- | ------------------------------------------- |
| -1 | The parameter check failed or system error. |
**Example** **Example**
```js ```js
try { try {
systemTime.getTimezone().then((data) => { systemTime.getTimezone().then((data) => {
console.info(`Succeeded in getting timezone: ${data}`); console.info(`Succeeded in getting timezone: ${data}`);
}).catch((error) => { }).catch((error) => {
console.info(`Failed to getting timezone. message:${error.message}, code:${error.code}`); console.info(`Failed to getting timezone. message: ${error.message}, code: ${error.code}`);
}); });
} catch(e) { } catch(e) {
console.info(`Failed to get timezone. message:${e.message}, code:${e.code}`); console.info(`Failed to get timezone. message: ${e.message}, code: ${e.code}`);
} }
``` ```
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
- [Event Error Codes](errorcode-CommonEventService.md) - [Event Error Codes](errorcode-CommonEventService.md)
- [DistributedNotificationService Error Codes](errorcode-DistributedNotificationService.md) - [DistributedNotificationService Error Codes](errorcode-DistributedNotificationService.md)
- UI Page - UI Page
- [Animator Error Codes](errorcode-animator.md)
- [promptAction Error Codes](errorcode-promptAction.md) - [promptAction Error Codes](errorcode-promptAction.md)
- [Router Error Codes](errorcode-router.md) - [Router Error Codes](errorcode-router.md)
- Graphics - Graphics
...@@ -73,6 +74,7 @@ ...@@ -73,6 +74,7 @@
- [Vibrator Error Codes](errorcode-vibrator.md) - [Vibrator Error Codes](errorcode-vibrator.md)
- [System Parameter Error Codes](errorcode-system-parameterV9.md) - [System Parameter Error Codes](errorcode-system-parameterV9.md)
- [USB Error Codes](errorcode-usb.md) - [USB Error Codes](errorcode-usb.md)
- [Update Error Codes](errorcode-update.md)
- Customization Management - Customization Management
- [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) - [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md)
- Language Base Class Library - Language Base Class Library
......
# Time and Time Zone Service Error Codes
## -1 Screen Unlock Error
**Error Message**
The parameter check failed or permission denied or system error.
**Description**
This error code is reported when a parameter check failure, permission verification failure, or system operation error occurs.
**Possible Cause**
1. The input parameter is invalid.
2. The required permission is not configured. For example, **ohos.permission.SET_TIME** is not configured for setting the time or **ohos.permission.SET_TIME_ZONE** is not configured for setting the time zone.
3. The system is not running properly due to a common kernel error, such as a memory allocation and multi-thread processing error.
**Solution**
1. Make sure input parameters are passed in as required.
2. Configure the **ohos.permission.SET_TIME** permission for setting the time and the **ohos.permission.SET_TIME_ZONE** permission for setting the time zone.
3. Make sure the memory is sufficient.
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册