diff --git a/en/application-dev/quick-start/start-with-ets-fa.md b/en/application-dev/quick-start/start-with-ets-fa.md
index 66f2ead3d35e72950a81c5495db14254210c8c2b..197765c3119690c7529469daa85a045d7c2853fd 100644
--- a/en/application-dev/quick-start/start-with-ets-fa.md
+++ b/en/application-dev/quick-start/start-with-ets-fa.md
@@ -223,7 +223,10 @@ You can implement page redirection through the [page router](../reference/apis/j
.height('5%')
// Bind the onClick event to the Next button so that clicking the button redirects the user to the second page.
.onClick(() => {
- router.pushUrl({ url: 'pages/second' })
+ router.push({ url: 'pages/second' })
+ // In a project of API version 9, you can use the API below instead:
+ // router.pushUrl({ url: 'pages/second' })
+
})
}
.width('100%')
diff --git a/en/application-dev/reference/apis/js-apis-screen-lock.md b/en/application-dev/reference/apis/js-apis-screen-lock.md
index c726ec7c8fdd4cd6f16d71f5a6892bc565b66cf6..aebd21314c8d71e68409b4b5d89af29161614950 100644
--- a/en/application-dev/reference/apis/js-apis-screen-lock.md
+++ b/en/application-dev/reference/apis/js-apis-screen-lock.md
@@ -100,14 +100,6 @@ Unlocks the screen. This API uses an asynchronous callback to return the result.
| -------- | --------------------- | ---- | ------------------------- |
| callback | AsyncCallback<boolean> | Yes | Callback used to return the result. The value **true** means that the screen is unlocked successfully, and **false** means the opposite.|
-**Error codes**
-
-For details about the error codes, see [Screen Lock Management Error Codes](../errorcodes/errorcode-screenlock.md).
-
-| ID| Error Message|
-| -------- | ---------------------------------------- |
-| 13200002 | The screenlock management service is abnormal. |
-
**Example**
```js
@@ -134,14 +126,6 @@ Unlocks the screen. This API uses a promise to return the result.
| ------------------- | ------------------------------------------------------------ |
| Promise<boolean> | Promise used to return the result. The value **true** means that the screen is unlocked successfully, and **false** means the opposite.|
-**Error codes**
-
-For details about the error codes, see [Screen Lock Management Error Codes](../errorcodes/errorcode-screenlock.md).
-
-| ID| Error Message|
-| -------- | ---------------------------------------- |
-| 13200002 | The screenlock management service is abnormal. |
-
**Example**
```js
@@ -168,14 +152,6 @@ Locks the screen. This API uses an asynchronous callback to return the result.
| -------- | ---------------------- | ---- | ---------------- |
| callback | AsyncCallback<boolean> | Yes | Callback used to return the result. The value **true** means that the screen is locked successfully, and **false** means the opposite.|
-**Error codes**
-
-For details about the error codes, see [Screen Lock Management Error Codes](../errorcodes/errorcode-screenlock.md).
-
-| ID| Error Message|
-| -------- | ---------------------------------------- |
-| 13200002 | The screenlock management service is abnormal. |
-
**Example**
```js
@@ -204,13 +180,6 @@ Locks the screen. This API uses a promise to return the result.
| ---------------------- | ------------------------------------------------------------ |
| Promise<boolean> | Promise used to return the result. The value **true** means that the screen is locked successfully, and **false** means the opposite.|
-**Error codes**
-
-For details about the error codes, see [Screen Lock Management Error Codes](../errorcodes/errorcode-screenlock.md).
-
-| ID| Error Message|
-| -------- | ---------------------------------------- |
-| 13200002 | The screenlock management service is abnormal. |
**Example**
@@ -226,7 +195,7 @@ screenlock.lock().then((data) => {
onSystemEvent(callback: Callback<SystemEvent>): boolean
-Registers a callback for system events related to screen locking.
+Registers a callback for system events related to screen locking. This API can be called only by system screen lock applications.
**System capability**: SystemCapability.MiscServices.ScreenLock
@@ -244,13 +213,6 @@ Registers a callback for system events related to screen locking.
| ------- | ------------------------------------------------- |
| boolean | Returns **true** if the callback is registered successfully; returns **false** otherwise.|
-**Error codes**
-
-For details about the error codes, see [Screen Lock Management Error Codes](../errorcodes/errorcode-screenlock.md).
-
-| ID| Error Message|
-| -------- | ---------------------------------------- |
-| 13200002 | The screenlock management service is abnormal. |
**Example**
@@ -282,13 +244,6 @@ Sends an event to the screen lock service. This API uses an asynchronous callbac
| parameter | number | Yes | Result. - **0**: The operation is successful. For example, the screen is locked or unlocked successfully. - **1**, the operation fails. For example, screen locking or unlocking fails. - **2**: The operation is canceled. For example, screen locking or unlocking is canceled.|
| callback | AsyncCallback\ | Yes | Callback used to return the result. The **value** true means that the event is sent successfully, and **false** means the opposite. |
-**Error codes**
-
-For details about the error codes, see [Screen Lock Management Error Codes](../errorcodes/errorcode-screenlock.md).
-
-| ID| Error Message|
-| -------- | ---------------------------------------- |
-| 13200002 | The screenlock management service is abnormal. |
**Example**
diff --git a/en/application-dev/reference/apis/js-apis-system-date-time.md b/en/application-dev/reference/apis/js-apis-system-date-time.md
index 90c915b32ee35f9d09f6fe0453c962b985f914f1..38d90b668894a52dde1a4ae05578d290182bc6ef 100644
--- a/en/application-dev/reference/apis/js-apis-system-date-time.md
+++ b/en/application-dev/reference/apis/js-apis-system-date-time.md
@@ -1,4 +1,4 @@
-# @ohos.systemDateTime
+# @ohos.systemDateTime (System Time and Time Zone)
The **systemDateTime** 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.
diff --git a/en/application-dev/reference/apis/js-apis-system-time.md b/en/application-dev/reference/apis/js-apis-system-time.md
index a1876af97b532bf208eb405ee9c7c22edda6919f..6454fd82ed851af06a70941cdf6ef68bf6af232a 100644
--- a/en/application-dev/reference/apis/js-apis-system-time.md
+++ b/en/application-dev/reference/apis/js-apis-system-time.md
@@ -1,4 +1,4 @@
-# @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.
@@ -29,25 +29,33 @@ Sets the system time. This API uses an asynchronous callback to return the resul
| time | number | Yes | Timestamp to set, in milliseconds. |
| 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**
```js
// Set the system time to 2021-01-20 02:36:25.
let time = 1611081385000;
try {
- systemTime.setTime(time, (error) => {
- if (error) {
- console.info(`Failed to setting time. message:${error.message}, code:${error.code}`);
- return;
- }
- console.info(`Succeeded in setting time`);
- });
+ systemTime.setTime(time, (error) => {
+ if (error) {
+ console.info(`Failed to setting time. message: ${error.message}, code: ${error.code}`);
+ return;
+ }
+ }console.info(`Succeeded in setting time`);
+ });
} 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}`);
}
```
-## systemTime.setTime(deprecated)
+## systemTime.setTime
setTime(time : number) : Promise<void>
@@ -69,67 +77,75 @@ Sets the system time. This API uses a promise to return the result.
| ------------------- | ------------------------- |
| 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**
```js
// Set the system time to 2021-01-20 02:36:25.
let time = 1611081385000;
try {
- systemTime.setTime(time).then(() => {
- console.info(`Succeeded in setting time.`);
- }).catch((error) => {
- console.info(`Failed to setting time. message:${error.message}, code:${error.code}`);
- });
+ systemTime.setTime(time).then(() => {
+ console.info(`Succeeded in setting time.`);
+ }).catch((error) => {
+ console.info(`Failed to setting time. message: ${error.message}, code: ${error.code}`);
+ });
} 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}`);
}
```
-## systemTime.getCurrentTime(deprecated)
+## systemTime.getCurrentTime8+
getCurrentTime(isNano: boolean, callback: AsyncCallback<number>): void
Obtains the time elapsed since the Unix epoch. This API uses an asynchronous callback to return the result.
-> **NOTE**
->
-> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [systemDateTime.getCurrentTime](./js-apis-system-date-time.md#systemdatetimegetcurrenttime).
-
**System capability**: SystemCapability.MiscServices.Time
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------- | ---- | ------------------ |
-| isNano | boolean | Yes | Whether the time to return is in nanoseconds. - **true**: in nanoseconds (ns). - **false**: in milliseconds (ms).|
+| isNano | boolean | Yes | Whether the time to return is in nanoseconds. - **true**: in nanoseconds. - **false**: in milliseconds.|
| callback | AsyncCallback<number> | 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**
```js
try {
- systemTime.getCurrentTime(true, (error, time) => {
- if (error) {
- console.info(`Failed to getting currentTime. message:${error.message}, code:${error.code}`);
- return;
- }
- console.info(`Succeeded in getting currentTime : ${time}`);
- });
+ systemTime.getCurrentTime(true, (error, time) => {
+ if (error) {
+ console.info(`Failed to getting currentTime. message: ${error.message}, code: ${error.code}`);
+ return;
+ }
+ console.info(`Succeeded in getting currentTime: ${time}`);
+ });
} 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}`);
}
```
-## systemTime.getCurrentTime(deprecated)
+## systemTime.getCurrentTime8+
getCurrentTime(callback: AsyncCallback<number>): void
Obtains the time elapsed since the Unix epoch. This API uses an asynchronous callback to return the result.
-> **NOTE**
->
-> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [systemDateTime.getCurrentTime](./js-apis-system-date-time.md#systemdatetimegetcurrenttime-1).
-
**System capability**: SystemCapability.MiscServices.Time
**Parameters**
@@ -138,39 +154,43 @@ Obtains the time elapsed since the Unix epoch. This API uses an asynchronous cal
| -------- | ----------- | ---- | ---------------------------------- |
| callback | AsyncCallback<number> | 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**
```js
try {
- systemTime.getCurrentTime((error, time) => {
- if (error) {
- console.info(`Failed to getting currentTime. message:${error.message}, code:${error.code}`);
- return;
- }
- console.info(`Succeeded in getting currentTime : ${time}`);
- });
+ systemTime.getCurrentTime((error, time) => {
+ if (error) {
+ console.info(`Failed to getting currentTime. message: ${error.message}, code: ${error.code}`);
+ return;
+ }
+ console.info(`Succeeded in getting currentTime : ${time}`);
+ });
} 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}`);
}
```
-## systemTime.getCurrentTime(deprecated)
+## systemTime.getCurrentTime8+
getCurrentTime(isNano?: boolean): Promise<number>
Obtains the time elapsed since the Unix epoch. This API uses a promise to return the result.
-> **NOTE**
->
-> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [systemDateTime.getCurrentTime](./js-apis-system-date-time.md#systemdatetimegetcurrenttime-2).
-
**System capability**: SystemCapability.MiscServices.Time
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------- | ---- | ------------------------- |
-| isNano | boolean | No | Whether the time to return is in nanoseconds. - **true**: in nanoseconds (ns). - **false**: in milliseconds (ms).|
+| isNano | boolean | No | Whether the time to return is in nanoseconds. - **true**: in nanoseconds. - **false**: in milliseconds.|
**Return value**
@@ -178,65 +198,73 @@ Obtains the time elapsed since the Unix epoch. This API uses a promise to return
| --------------------- | --------------------------- |
| Promise<number> | 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**
```js
try {
- systemTime.getCurrentTime().then((time) => {
- console.info(`Succeeded in getting currentTime : ${time}`);
- }).catch((error) => {
- console.info(`Failed to getting currentTime. message:${error.message}, code:${error.code}`);
- });
+ systemTime.getCurrentTime().then((time) => {
+ console.info(`Succeeded in getting currentTime : ${time}`);
+ }).catch((error) => {
+ console.info(`Failed to getting currentTime. message: ${error.message}, code: ${error.code}`);
+ });
} 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}`);
}
```
-## systemTime.getRealActiveTime(deprecated)
+## systemTime.getRealActiveTime8+
getRealActiveTime(isNano: boolean, callback: AsyncCallback<number>): void
Obtains the time elapsed since system startup, excluding the deep sleep time. This API uses an asynchronous callback to return the result.
-> **NOTE**
->
-> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [systemDateTime.getRealActiveTime](./js-apis-system-date-time.md#systemdatetimegetrealactivetime).
-
**System capability**: SystemCapability.MiscServices.Time
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------- | ---- | -------------------------- |
-| isNano | boolean | Yes | Whether the time to return is in nanoseconds. - **true**: in nanoseconds (ns). - **false**: in milliseconds (ms).|
+| isNano | boolean | Yes | Whether the time to return is in nanoseconds. - **true**: in nanoseconds. - **false**: in milliseconds.|
| callback | AsyncCallback<number> | 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**
```js
try {
- systemTime.getRealActiveTime(true, (error, time) => {
- if (error) {
- console.info(`Failed to getting real active time. message:${error.message}, code:${error.code}`);
- return;
- }
- console.info(`Succeeded in getting real active time : ${time}`);
- });
+ systemTime.getRealActiveTime(true, (error, time) => {
+ if (error) {
+ console.info(`Failed to getting real active time. message: ${error.message}, code: ${error.code}`);
+ return;
+ }
+ console.info(`Succeeded in getting real active time : ${time}`);
+ });
} 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}`);
}
```
-## systemTime.getRealActiveTime(deprecated)
+## systemTime.getRealActiveTime8+
getRealActiveTime(callback: AsyncCallback<number>): void
Obtains the time elapsed since system startup, excluding the deep sleep time. This API uses an asynchronous callback to return the result.
-> **NOTE**
->
-> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [systemDateTime.getRealActiveTime](./js-apis-system-date-time.md#systemdatetimegetrealactivetime-1).
-
**System capability**: SystemCapability.MiscServices.Time
**Parameters**
@@ -245,39 +273,43 @@ Obtains the time elapsed since system startup, excluding the deep sleep time. Th
| -------- | -------------- | ---- | --------------------- |
| callback | AsyncCallback<number> | 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**
```js
try {
- systemTime.getRealActiveTime((error, time) => {
- if (error) {
- console.info(`Failed to getting real active time. message:${error.message}, code:${error.code}`);
- return;
- }
- console.info(`Succeeded in getting real active time : ${time}`);
- });
+ systemTime.getRealActiveTime((error, time) => {
+ if (error) {
+ console.info(`Failed to getting real active time. message: ${error.message}, code: ${error.code}`);
+ return;
+ }
+ console.info(`Succeeded in getting real active time : ${time}`);
+ });
} 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}`);
}
```
-## systemTime.getRealActiveTime(deprecated)
+## systemTime.getRealActiveTime8+
getRealActiveTime(isNano?: boolean): Promise<number>
Obtains the time elapsed since system startup, excluding the deep sleep time. This API uses a promise to return the result.
-> **NOTE**
->
-> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [systemDateTime.getRealActiveTime](./js-apis-system-date-time.md#systemdatetimegetrealactivetime-2).
-
**System capability**: SystemCapability.MiscServices.Time
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------- | ---- | ----------------------------------- |
-| isNano | boolean | No | Whether the time to return is in nanoseconds. - **true**: in nanoseconds (ns). - **false**: in milliseconds (ms).|
+| isNano | boolean | No | Whether the time to return is in nanoseconds. - **true**: in nanoseconds. - **false**: in milliseconds.|
**Return value**
@@ -285,65 +317,73 @@ Obtains the time elapsed since system startup, excluding the deep sleep time. Th
| -------------- | -------------------------------- |
| Promise<number> | 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**
```js
try {
- systemTime.getRealActiveTime().then((time) => {
- console.info(`Succeeded in getting real active time : ${time}`);
- }).catch((error) => {
- console.info(`Failed to getting real active time. message:${error.message}, code:${error.code}`);
- });
+ systemTime.getRealActiveTime().then((time) => {
+ console.info(`Succeeded in getting real active time : ${time}`);
+ }).catch((error) => {
+ console.info(`Failed to getting real active time. message: ${error.message}, code: ${error.code}`);
+ });
} 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}`);
}
```
-## systemTime.getRealTime(deprecated)
+## systemTime.getRealTime8+
getRealTime(isNano: boolean, callback: AsyncCallback<number>): void
Obtains the time elapsed since system startup, including the deep sleep time. This API uses an asynchronous callback to return the result.
-> **NOTE**
->
-> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [systemDateTime.getRealTime](./js-apis-system-date-time.md#systemdatetimegetrealtime).
-
**System capability**: SystemCapability.MiscServices.Time
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------- | ---- | ------------------------------- |
-| isNano | boolean | Yes | Whether the time to return is in nanoseconds. - **true**: in nanoseconds (ns). - **false**: in milliseconds (ms).|
+| isNano | boolean | Yes | Whether the time to return is in nanoseconds. - **true**: in nanoseconds. - **false**: in milliseconds.|
| callback | AsyncCallback<number> | 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**
```js
try {
- systemTime.getRealTime(true, (error, time) => {
- if (error) {
- console.info(`Failed to getting real time. message:${error.message}, code:${error.code}`);
- return;
- }
- console.info(`Succeeded in getting real time : ${time}`);
- });
+ systemTime.getRealTime(true, (error, time) => {
+ if (error) {
+ console.info(`Failed to getting real time. message: ${error.message}, code: ${error.code}`);
+ return;
+ }
+ console.info(`Succeeded in getting real time : ${time}`);
+ });
} 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}`);
}
```
-## systemTime.getRealTime(deprecated)
+## systemTime.getRealTime8+
getRealTime(callback: AsyncCallback<number>): void
Obtains the time elapsed since system startup, including the deep sleep time. This API uses an asynchronous callback to return the result.
-> **NOTE**
->
-> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [systemDateTime.getRealTime](./js-apis-system-date-time.md#systemdatetimegetrealtime-1).
-
**System capability**: SystemCapability.MiscServices.Time
**Parameters**
@@ -352,39 +392,43 @@ Obtains the time elapsed since system startup, including the deep sleep time. Th
| -------- | --------- | ---- | --------------------------- |
| callback | AsyncCallback<number> | 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**
```js
try {
- systemTime.getRealTime((error, time) => {
- if (error) {
- console.info(`Failed to getting real time. message:${error.message}, code:${error.code}`);
- return;
- }
- console.info(`Succeeded in getting real time : ${time}`);
- });
+ systemTime.getRealTime((error, time) => {
+ if (error) {
+ console.info(`Failed to getting real time. message: ${error.message}, code: ${error.code}`);
+ return;
+ }
+ console.info(`Succeeded in getting real time : ${time}`);
+ });
} 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}`);
}
```
-## systemTime.getRealTime(deprecated)
+## systemTime.getRealTime8+
getRealTime(isNano?: boolean): Promise<number>
Obtains the time elapsed since system startup, including the deep sleep time. This API uses a promise to return the result.
-> **NOTE**
->
-> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [systemDateTime.getRealTime](./js-apis-system-date-time.md#systemdatetimegetrealtime-2).
-
**System capability**: SystemCapability.MiscServices.Time
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------- | ---- | ------------------------------- |
-| isNano | boolean | No | Whether the time to return is in nanoseconds. - **true**: in nanoseconds (ns). - **false**: in milliseconds (ms).|
+| isNano | boolean | No | Whether the time to return is in nanoseconds. - **true**: in nanoseconds. - **false**: in milliseconds.|
**Return value**
@@ -392,21 +436,29 @@ Obtains the time elapsed since system startup, including the deep sleep time. Th
| --------------------- | ------------------------------- |
| Promise<number> | 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**
```js
try {
- systemTime.getRealTime().then((time) => {
- console.info(`Succeeded in getting real time : ${time}`);
- }).catch((error) => {
- console.info(`Failed to getting real time. message:${error.message}, code:${error.code}`);
- });
+ systemTime.getRealTime().then((time) => {
+ console.info(`Succeeded in getting real time : ${time}`);
+ }).catch((error) => {
+ console.info(`Failed to getting real time. message: ${error.message}, code: ${error.code}`);
+ });
} 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}`);
}
```
-## systemTime.setDate(deprecated)
+## systemTime.setDate
setDate(date: Date, callback: AsyncCallback<void>): void
@@ -423,24 +475,32 @@ Sets the system date. This API uses an asynchronous callback to return the resul
| date | Date | Yes | Target date to set. |
| 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**
```js
let date = new Date();
try {
- systemTime.setDate(date, (error) => {
- if (error) {
- console.info(`Failed to setting date. message:${error.message}, code:${error.code}`);
- return;
- }
- console.info(`Succeeded in setting date.`);
- });
+ systemTime.setDate(date, (error) => {
+ if (error) {
+ console.info(`Failed to setting date. message: ${error.message}, code: ${error.code}`);
+ return;
+ }
+ console.info(`Succeeded in setting date.`);
+ });
} 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}`);
}
```
-## systemTime.setDate(deprecated)
+## systemTime.setDate
setDate(date: Date): Promise<void>
@@ -462,31 +522,35 @@ Sets the system date. This API uses a promise to return the result.
| ------------------- | -------------------- |
| 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**
```js
let date = new Date();
try {
- systemTime.setDate(date).then(() => {
- console.info(`Succeeded in setting date.`);
- }).catch((error) => {
- console.info(`Failed to setting date. message:${error.message}, code:${error.code}`);
- });
+ systemTime.setDate(date).then(() => {
+ console.info(`Succeeded in setting date.`);
+ }).catch((error) => {
+ console.info(`Failed to setting date. message: ${error.message}, code: ${error.code}`);
+ });
} 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}`);
}
```
-## systemTime.getDate(deprecated)
+## systemTime.getDate8+
getDate(callback: AsyncCallback<Date>): void
Obtains the current system date. This API uses an asynchronous callback to return the result.
-> **NOTE**
->
-> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [systemDateTime.getDate](./js-apis-system-date-time.md#systemdatetimegetdate).
-
**System capability**: SystemCapability.MiscServices.Time
**Parameters**
@@ -495,32 +559,36 @@ Obtains the current system date. This API uses an asynchronous callback to retur
| -------- | -------------- | ---- | --------------------- |
| callback | AsyncCallback<Date> | 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**
```js
try {
- systemTime.getDate((error, date) => {
- if (error) {
- console.info(`Failed to get date. message:${error.message}, code:${error.code}`);
- return;
- }
- console.info(`Succeeded in get date : ${date}`);;
- });
+ systemTime.getDate((error, date) => {
+ if (error) {
+ console.info(`Failed to get date. message: ${error.message}, code: ${error.code}`);
+ return;
+ }
+ console.info(`Succeeded in get date : ${date}`);;
+ });
} 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}`);
}
```
-## systemTime.getDate(deprecated)
+## systemTime.getDate8+
getDate(): Promise<Date>
Obtains the current system date. This API uses a promise to return the result.
-> **NOTE**
->
-> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [systemDateTime.getDate](./js-apis-system-date-time.md#systemdatetimegetdate-1).
-
**System capability**: SystemCapability.MiscServices.Time
**Return value**
@@ -529,21 +597,29 @@ Obtains the current system date. This API uses a promise to return the result.
| ------------------- | ----------------------------------------- |
| Promise<Date> | 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**
```js
try {
- systemTime.getDate().then((date) => {
- console.info(`Succeeded in getting date : ${date}`);
- }).catch((error) => {
- console.info(`Failed to getting date. message:${error.message}, code:${error.code}`);
- });
+ systemTime.getDate().then((date) => {
+ console.info(`Succeeded in getting date : ${date}`);
+ }).catch((error) => {
+ console.info(`Failed to getting date. message: ${error.message}, code: ${error.code}`);
+ });
} 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}`);
}
```
-## systemTime.setTimezone(deprecated)
+## systemTime.setTimezone
setTimezone(timezone: string, callback: AsyncCallback<void>): void
@@ -560,23 +636,31 @@ 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). |
| 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**
```js
try {
- systemTime.setTimezone('Asia/Shanghai', (error) => {
- if (error) {
- console.info(`Failed to setting timezone. message:${error.message}, code:${error.code}`);
- return;
- }
- console.info(`Succeeded in setting timezone.`);
- });
+ systemTime.setTimezone('Asia/Shanghai', (error) => {
+ if (error) {
+ console.info(`Failed to setting timezone. message: ${error.message}, code: ${error.code}`);
+ return;
+ }
+ console.info(`Succeeded in setting timezone.`);
+ });
} 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}`);
}
```
-## systemTime.setTimezone(deprecated)
+## systemTime.setTimezone
setTimezone(timezone: string): Promise<void>
@@ -598,30 +682,34 @@ Sets the system time zone. This API uses a promise to return the result.
| ------------------- | -------------------- |
| 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**
```js
try {
- systemTime.setTimezone('Asia/Shanghai').then(() => {
- console.info(`Succeeded in setting timezone.`);
- }).catch((error) => {
- console.info(`Failed to setting timezone. message:${error.message}, code:${error.code}`);
- });
+ systemTime.setTimezone('Asia/Shanghai').then(() => {
+ console.info(`Succeeded in setting timezone.`);
+ }).catch((error) => {
+ console.info(`Failed to setting timezone. message: ${error.message}, code: ${error.code}`);
+ });
} 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}`);
}
```
-## systemTime.getTimezone(deprecated)
+## systemTime.getTimezone8+
getTimezone(callback: AsyncCallback<string>): void
Obtains the system time zone. This API uses an asynchronous callback to return the result.
-> **NOTE**
->
-> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [systemDateTime.getTimezone](./js-apis-system-date-time.md#systemdatetimegettimezone).
-
**System capability**: SystemCapability.MiscServices.Time
**Parameters**
@@ -630,32 +718,36 @@ Obtains the system time zone. This API uses an asynchronous callback to return t
| -------- | --------- | ---- | ------------------------ |
| callback | AsyncCallback<string> | 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**
```js
try {
- systemTime.getTimezone((error, data) => {
- if (error) {
- console.info(`Failed to get timezone. message:${error.message}, code:${error.code}`);
- return;
- }
- console.info(`Succeeded in get timezone : ${data}`);;
- });
+ systemTime.getTimezone((error, data) => {
+ if (error) {
+ console.info(`Failed to get timezone. message: ${error.message}, code: ${error.code}`);
+ return;
+ }
+ console.info(`Succeeded in get timezone : ${data}`);;
+ });
} 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}`);
}
```
-## systemTime.getTimezone(deprecated)
+## systemTime.getTimezone8+
getTimezone(): Promise<string>
Obtains the system time zone. This API uses a promise to return the result.
-> **NOTE**
->
-> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [systemDateTime.getTimezone](./js-apis-system-date-time.md#systemdatetimegettimezone-1).
-
**System capability**: SystemCapability.MiscServices.Time
**Return value**
@@ -664,17 +756,25 @@ Obtains the system time zone. This API uses a promise to return the result.
| --------------------- | ------------------------------------- |
| Promise<string> | 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**
```js
try {
- systemTime.getTimezone().then((data) => {
- console.info(`Succeeded in getting timezone: ${data}`);
- }).catch((error) => {
- console.info(`Failed to getting timezone. message:${error.message}, code:${error.code}`);
- });
+ systemTime.getTimezone().then((data) => {
+ console.info(`Succeeded in getting timezone: ${data}`);
+ }).catch((error) => {
+ console.info(`Failed to getting timezone. message: ${error.message}, code: ${error.code}`);
+ });
} 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}`);
}
```
diff --git a/en/application-dev/reference/apis/js-apis-system-timer.md b/en/application-dev/reference/apis/js-apis-system-timer.md
index fb1f95ce2d8c5003377120d9d28f29f4415d3117..cb3a97212ef21d604ae41784f142ac60fcf3f353 100644
--- a/en/application-dev/reference/apis/js-apis-system-timer.md
+++ b/en/application-dev/reference/apis/js-apis-system-timer.md
@@ -1,4 +1,4 @@
-# @ohos.systemTimer
+# @ohos.systemTimer (System Timer)
The **systemTimer** module provides system timer features. You can use the APIs of this module to implement the alarm clock and other timer services.
@@ -48,8 +48,6 @@ createTimer(options: TimerOptions, callback: AsyncCallback<number>): void
Creates a timer. This API uses an asynchronous callback to return the result.
-**System API**: This is a system API.
-
**System capability**: SystemCapability.MiscServices.Time
**Parameters**
@@ -63,23 +61,23 @@ Creates a timer. This API uses an asynchronous callback to return the result.
```js
export default {
- systemTimer () {
- let options = {
- type: systemTimer.TIMER_TYPE_REALTIME,
- repeat: false
- };
- try {
- systemTimer.createTimer(options, (error) => {
- if (error) {
- console.info(`Failed to create timer. message:${error.message}, code:${error.code}`);
- return;
- }
- console.info(`Succeeded in creating timer.`);
- });
- } catch(e) {
- console.info(`Failed to create timer. message:${e.message}, code:${e.code}`);
+ systemTimer () {
+ let options = {
+ type: systemTimer.TIMER_TYPE_REALTIME,
+ repeat: false
+ };
+ try {
+ systemTimer.createTimer(options, (error, timerId) => {
+ if (error) {
+ console.info(`Failed to create timer. message: ${error.message}, code: ${error.code}`);
+ return;
}
+ console.info(`Succeeded in creating timer. timerId: ${timerId}`);
+ });
+ } catch(e) {
+ console.info(`Failed to create timer. message: ${e.message}, code: ${e.code}`);
}
+ }
}
```
@@ -89,8 +87,6 @@ createTimer(options: TimerOptions): Promise<number>
Creates a timer. This API uses a promise to return the result.
-**System API**: This is a system API.
-
**System capability**: SystemCapability.MiscServices.Time
**Parameters**
@@ -109,21 +105,21 @@ Creates a timer. This API uses a promise to return the result.
```js
export default {
- systemTimer () {
- let options = {
- type: systemTimer.TIMER_TYPE_REALTIME,
- repeat:false
- };
- try {
- systemTimer.createTimer(options).then(() => {
- console.info(`Succeeded in creating timer.`);
- }).catch((error) => {
- console.info(`Failed to create timer. message:${error.message}, code:${error.code}`);
- });
- } catch(e) {
- console.info(`Failed to create timer. message:${e.message}, code:${e.code}`);
- }
+ systemTimer () {
+ let options = {
+ type: systemTimer.TIMER_TYPE_REALTIME,
+ repeat:false
+ };
+ try {
+ systemTimer.createTimer(options).then((timerId) => {
+ console.info(`Succeeded in creating timer. timerId: ${timerId}`);
+ }).catch((error) => {
+ console.info(`Failed to create timer. message: ${error.message}, code: ${error.code}`);
+ });
+ } catch(e) {
+ console.info(`Failed to create timer. message: ${e.message}, code: ${e.code}`);
}
+ }
}
```
@@ -133,8 +129,6 @@ startTimer(timer: number, triggerTime: number, callback: AsyncCallback<void&g
Starts a timer. This API uses an asynchronous callback to return the result.
-**System API**: This is a system API.
-
**System capability**: SystemCapability.MiscServices.Time
**Parameters**
@@ -149,26 +143,26 @@ Starts a timer. This API uses an asynchronous callback to return the result.
```js
export default {
- async systemTimer () {
- let options = {
- type: systemTimer.TIMER_TYPE_REALTIME,
- repeat:false
+ async systemTimer () {
+ let options = {
+ type: systemTimer.TIMER_TYPE_REALTIME,
+ repeat:false
+ }
+ let timerId = await systemTimer.createTimer(options);
+ let triggerTime = new Date().getTime();
+ triggerTime += 3000;
+ try {
+ systemTimer.startTimer(timerId, triggerTime, (error) => {
+ if (error) {
+ console.info(`Failed to start timer. message: ${error.message}, code: ${error.code}`);
+ return;
}
- let timerId = await systemTimer.createTimer(options)
- let triggerTime = new Date().getTime()
- triggerTime += 3000
- try {
- systemTimer.startTimer(timerId, triggerTime, (error) => {
- if (error) {
- console.info(`Failed to start timer. message:${error.message}, code:${error.code}`);
- return;
- }
- console.info(`Succeeded in starting timer.`);
- });
- } catch(e) {
- console.info(`Failed to start timer. message:${e.message}, code:${e.code}`);
- }
+ console.info(`Succeeded in starting timer.`);
+ });
+ } catch(e) {
+ console.info(`Failed to start timer. message: ${e.message}, code: ${e.code}`);
}
+ }
}
```
@@ -178,8 +172,6 @@ startTimer(timer: number, triggerTime: number): Promise<void>
Starts a timer. This API uses a promise to return the result.
-**System API**: This is a system API.
-
**System capability**: SystemCapability.MiscServices.Time
**Parameters**
@@ -199,24 +191,24 @@ Starts a timer. This API uses a promise to return the result.
```js
export default {
- async systemTimer (){
- let options = {
- type: systemTimer.TIMER_TYPE_REALTIME,
- repeat:false
- }
- let timerId = await systemTimer.createTimer(options)
- let triggerTime = new Date().getTime()
- triggerTime += 3000
- try {
- systemTimer.startTimer(timerId, triggerTime).then(() => {
- console.info(`Succeeded in starting timer.`);
- }).catch((error) => {
- console.info(`Failed to start timer. message:${error.message}, code:${error.code}`);
- });
- } catch(e) {
- console.info(`Failed to start timer. message:${e.message}, code:${e.code}`);
- }
+ async systemTimer (){
+ let options = {
+ type: systemTimer.TIMER_TYPE_REALTIME,
+ repeat:false
}
+ let timerId = await systemTimer.createTimer(options);
+ let triggerTime = new Date().getTime();
+ triggerTime += 3000;
+ try {
+ systemTimer.startTimer(timerId, triggerTime).then(() => {
+ console.info(`Succeeded in starting timer.`);
+ }).catch((error) => {
+ console.info(`Failed to start timer. message: ${error.message}, code: ${error.code}`);
+ });
+ } catch(e) {
+ console.info(`Failed to start timer. message: ${e.message}, code: ${e.code}`);
+ }
+ }
}
```
@@ -226,8 +218,6 @@ stopTimer(timer: number, callback: AsyncCallback<void>): void
Stops a timer. This API uses an asynchronous callback to return the result.
-**System API**: This is a system API.
-
**System capability**: SystemCapability.MiscServices.Time
**Parameters**
@@ -241,27 +231,27 @@ Stops a timer. This API uses an asynchronous callback to return the result.
```js
export default {
- async systemTimer () {
- let options = {
- type: systemTimer.TIMER_TYPE_REALTIME,
- repeat:false
- }
- let timerId = await systemTimer.createTimer(options)
- let triggerTime = new Date().getTime()
- triggerTime += 3000
- systemTimer.startTimer(timerId, triggerTime)
- try {
- systemTimer.stopTimer(timerId, (error) => {
- if (error) {
- console.info(`Failed to stop timer. message:${error.message}, code:${error.code}`);
- return;
- }
- console.info(`Succeeded in stopping timer.`);
- });
- } catch(e) {
- console.info(`Failed to stop timer. message:${e.message}, code:${e.code}`);
+ async systemTimer () {
+ let options = {
+ type: systemTimer.TIMER_TYPE_REALTIME,
+ repeat:false
+ }
+ let timerId = await systemTimer.createTimer(options);
+ let triggerTime = new Date().getTime();
+ triggerTime += 3000;
+ systemTimer.startTimer(timerId, triggerTime);
+ try {
+ systemTimer.stopTimer(timerId, (error) => {
+ if (error) {
+ console.info(`Failed to stop timer. message: ${error.message}, code: ${error.code}`);
+ return;
}
- }
+ console.info(`Succeeded in stopping timer.`);
+ });
+ } catch(e) {
+ console.info(`Failed to stop timer. message: ${e.message}, code: ${e.code}`);
+ }
+ }
}
```
@@ -271,8 +261,6 @@ stopTimer(timer: number): Promise<void>
Stops a timer. This API uses a promise to return the result.
-**System API**: This is a system API.
-
**System capability**: SystemCapability.MiscServices.Time
**Parameters**
@@ -291,25 +279,25 @@ Stops a timer. This API uses a promise to return the result.
```js
export default {
- async systemTimer (){
- let options = {
- type: systemTimer.TIMER_TYPE_REALTIME,
- repeat:false
- }
- let timerId = await systemTimer.createTimer(options)
- let triggerTime = new Date().getTime()
- triggerTime += 3000
- systemTimer.startTimer(timerId, triggerTime)
- try {
- systemTimer.stopTimer(timerId).then(() => {
- console.info(`Succeeded in stopping timer.`);
- }).catch((error) => {
- console.info(`Failed to stop timer. message:${error.message}, code:${error.code}`);
- });
- } catch(e) {
- console.info(`Failed to stop timer. message:${e.message}, code:${e.code}`);
- }
+ async systemTimer (){
+ let options = {
+ type: systemTimer.TIMER_TYPE_REALTIME,
+ repeat:false
}
+ let timerId = await systemTimer.createTimer(options);
+ let triggerTime = new Date().getTime();
+ triggerTime += 3000;
+ systemTimer.startTimer(timerId, triggerTime);
+ try {
+ systemTimer.stopTimer(timerId).then(() => {
+ console.info(`Succeeded in stopping timer.`);
+ }).catch((error) => {
+ console.info(`Failed to stop timer. message: ${error.message}, code: ${error.code}`);
+ });
+ } catch(e) {
+ console.info(`Failed to stop timer. message: ${e.message}, code: ${e.code}`);
+ }
+ }
}
```
@@ -319,8 +307,6 @@ destroyTimer(timer: number, callback: AsyncCallback<void>): void
Destroys a timer. This API uses an asynchronous callback to return the result.
-**System API**: This is a system API.
-
**System capability**: SystemCapability.MiscServices.Time
**Parameters**
@@ -334,28 +320,28 @@ Destroys a timer. This API uses an asynchronous callback to return the result.
```js
export default {
- async systemTimer () {
- let options = {
- type: systemTimer.TIMER_TYPE_REALTIME,
- repeat:false
- }
- let timerId = await systemTimer.createTimer(options)
- let triggerTime = new Date().getTime()
- triggerTime += 3000
- systemTimer.startTimer(timerId, triggerTime)
- systemTimer.stopTimer(timerId)
- try {
- systemTimer.destroyTimer(timerId, (error) => {
- if (error) {
- console.info(`Failed to destroy timer. message:${error.message}, code:${error.code}`);
- return;
- }
- console.info(`Succeeded in destroying timer.`);
- });
- } catch(e) {
- console.info(`Failed to destroying timer. message:${e.message}, code:${e.code}`);
+ async systemTimer () {
+ let options = {
+ type: systemTimer.TIMER_TYPE_REALTIME,
+ repeat:false
+ }
+ let timerId = await systemTimer.createTimer(options);
+ let triggerTime = new Date().getTime();
+ triggerTime += 3000;
+ systemTimer.startTimer(timerId, triggerTime);
+ systemTimer.stopTimer(timerId);
+ try {
+ systemTimer.destroyTimer(timerId, (error) => {
+ if (error) {
+ console.info(`Failed to destroy timer. message: ${error.message}, code: ${error.code}`);
+ return;
}
+ console.info(`Succeeded in destroying timer.`);
+ });
+ } catch(e) {
+ console.info(`Failed to destroying timer. message: ${e.message}, code: ${e.code}`);
}
+ }
}
```
@@ -365,8 +351,6 @@ destroyTimer(timer: number): Promise<void>
Destroys a timer. This API uses a promise to return the result.
-**System API**: This is a system API.
-
**System capability**: SystemCapability.MiscServices.Time
**Parameters**
@@ -385,25 +369,25 @@ Destroys a timer. This API uses a promise to return the result.
```js
export default {
- async systemTimer (){
- let options = {
- type: systemTimer.TIMER_TYPE_REALTIME,
- repeat:false
- }
- let timerId = await systemTimer.createTimer(options)
- let triggerTime = new Date().getTime()
- triggerTime += 3000
- systemTimer.startTimer(timerId, triggerTime)
- systemTimer.stopTimer(timerId)
- try {
- systemTimer.destroyTimer(timerId).then(() => {
- console.info(`Succeeded in destroying timer.`);
- }).catch((error) => {
- console.info(`Failed to destroy timer. message:${error.message}, code:${error.code}`);
- });
- } catch(e) {
- console.info(`Failed to destroying timer. message:${e.message}, code:${e.code}`);
- }
+ async systemTimer (){
+ let options = {
+ type: systemTimer.TIMER_TYPE_REALTIME,
+ repeat:false
+ }
+ let timerId = await systemTimer.createTimer(options);
+ let triggerTime = new Date().getTime();
+ triggerTime += 3000;
+ systemTimer.startTimer(timerId, triggerTime);
+ systemTimer.stopTimer(timerId);
+ try {
+ systemTimer.destroyTimer(timerId).then(() => {
+ console.info(`Succeeded in destroying timer.`);
+ }).catch((error) => {
+ console.info(`Failed to destroy timer. message: ${error.message}, code: ${error.code}`);
+ });
+ } catch(e) {
+ console.info(`Failed to destroying timer. message: ${e.message}, code: ${e.code}`);
}
+ }
}
```
diff --git a/en/application-dev/reference/apis/js-apis-webview.md b/en/application-dev/reference/apis/js-apis-webview.md
index 83d89392cd8ade90901018fbe5721ce53ba54f2e..8c3ca939bdb5758f987780d94c7bb88837613b4d 100644
--- a/en/application-dev/reference/apis/js-apis-webview.md
+++ b/en/application-dev/reference/apis/js-apis-webview.md
@@ -1,6 +1,6 @@
-# @ohos.web.webview
+# @ohos.web.webview (Webview)
The **Webview** module provides APIs for web control.
@@ -228,19 +228,19 @@ Loads the dynamic link library (DLL) file of the web engine. This API can be cal
**Example**
-The following code snippet exemplifies calling this API after the EntryAbility is created.
+The following code snippet exemplifies calling this API after the MainAbility is created.
```ts
// xxx.ts
-import UIAbility from '@ohos.app.ability.UIAbility';
-import web_webview from '@ohos.web.webview';
+import Ability from '@ohos.application.Ability'
+import web_webview from '@ohos.web.webview'
-export default class EntryAbility extends UIAbility {
+export default class MainAbility extends Ability {
onCreate(want, launchParam) {
- console.log("EntryAbility onCreate")
+ console.log("MainAbility onCreate")
web_webview.WebviewController.initializeWebEngine()
globalThis.abilityWant = want
- console.log("EntryAbility onCreate done")
+ console.log("MainAbility onCreate done")
}
}
```
@@ -249,7 +249,7 @@ export default class EntryAbility extends UIAbility {
```ts
// xxx.ets
-import web_webview from '@ohos.web.webview';
+import web_webview from '@ohos.web.webview'
@Entry
@Component
@@ -1471,10 +1471,8 @@ struct WebComponent {
try {
// 1. Create two message ports.
this.ports = this.controller.createWebMessagePorts();
- // 2. Send one of the message ports to the HTML side, which can then save and use the port.
- this.controller.postMessage('__init_port__', [this.ports[0]], '*');
- // 3. Register a callback for the other message port on the application side.
- this.ports[1].onMessageEvent((result: WebMessage) => {
+ // 2. Register a callback on a message port (for example, port 1) on the application side.
+ this.ports[1].onMessageEvent((result: web_webview.WebMessage) => {
var msg = 'Got msg from HTML:';
if (typeof(result) == "string") {
console.log("received string message from html5, string is:" + result);
@@ -1491,12 +1489,14 @@ struct WebComponent {
}
this.receivedFromHtml = msg;
})
+ // 3. Send another message port (for example, port 0) to the HTML side, which can then save the port for future use.
+ this.controller.postMessage('__init_port__', [this.ports[0]], '*');
} catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
}
})
- // 4. Use the port on the application side to send messages to the message port that has been sent to the HTML.
+ // 4. Use the port on the application side to send messages to the port that has been sent to the HTML side.
Button('SendDataToHTML')
.onClick(() => {
try {
@@ -1506,7 +1506,7 @@ struct WebComponent {
console.error(`ports is null, Please initialize first`);
}
} catch (error) {
- console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
+ console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
}
})
Web({ src: $rawfile('xxx.html'), controller: this.controller })
@@ -1528,7 +1528,7 @@ struct WebComponent {