提交 424e39c5 编写于 作者: W wangtong

回合monthly

Signed-off-by: Nwangtong <wangtong94@huawei.com>
上级 e5d7149a
# @ohos.systemDateTime (系统时间、时区)
本模块主要由系统时间和系统时区功能组成。开发者可以设置、获取系统时间及系统时区。
> **说明:**
>
> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
## 导入模块
```js
import systemDateTime from '@ohos.systemDateTime';
```
## systemDateTime.setTime
setTime(time : number, callback : AsyncCallback&lt;void&gt;) : void
设置系统时间,使用callback异步回调。
**系统接口:** 此接口为系统接口
**系统能力:** SystemCapability.MiscServices.Time
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------- | ---- | ---------------- |
| time | number | 是 | 目标时间戳(ms)。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。 |
**示例:**
```js
// time对应的时间为2021-01-20 02:36:25
let time = 1611081385000;
try {
systemDateTime.setTime(time, (error) => {
if (error) {
console.info(`Failed to set 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}`);
}
```
## systemDateTime.setTime
setTime(time : number) : Promise&lt;void&gt;
设置系统时间,使用Promise异步回调。
**系统接口:** 此接口为系统接口
**系统能力:** SystemCapability.MiscServices.Time
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------ | ---- | ------------------ |
| time | number | 是 | 目标时间戳(ms)。 |
**返回值:**
| 类型 | 说明 |
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
**示例:**
```js
// time对应的时间为2021-01-20 02:36:25
let time = 1611081385000;
try {
systemDateTime.setTime(time).then(() => {
console.info(`Succeeded in setting time.`);
}).catch((error) => {
console.info(`Failed to set time. message:${error.message}, code:${error.code}`);
});
} catch(e) {
console.info(`Failed to set time. message:${e.message}, code:${e.code}`);
}
```
## systemDateTime.getCurrentTime
getCurrentTime(isNano: boolean, callback: AsyncCallback&lt;number&gt;): void
获取自Unix纪元以来经过的时间,使用callback异步回调。
**系统能力:** SystemCapability.MiscServices.Time
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------- | ---- | ------------------ |
| isNano | boolean | 是 | 返回结果是否为纳秒数。<br>- true:表示返回结果为纳秒数(ns)。 <br>- false:表示返回结果为毫秒数(ms)。 |
| callback | AsyncCallback&lt;number&gt; | 是 | 回调函数,返回自Unix纪元以来经过的时间。 |
**示例:**
```js
try {
systemDateTime.getCurrentTime(true, (error, time) => {
if (error) {
console.info(`Failed to get 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}`);
}
```
## systemDateTime.getCurrentTime
getCurrentTime(callback: AsyncCallback&lt;number&gt;): void
获取自Unix纪元以来经过的时间,使用callback异步回调。
**系统能力:** SystemCapability.MiscServices.Time
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------- | ---- | ---------------------------------- |
| callback | AsyncCallback&lt;number&gt; | 是 | 回调函数,返回自Unix纪元以来经过的时间。 |
**示例:**
```js
try {
systemDateTime.getCurrentTime((error, time) => {
if (error) {
console.info(`Failed to get 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}`);
}
```
## systemDateTime.getCurrentTime
getCurrentTime(isNano?: boolean): Promise&lt;number&gt;
获取自Unix纪元以来经过的时间,使用Promise异步回调。
**系统能力:** SystemCapability.MiscServices.Time
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------- | ---- | ------------------------- |
| isNano | boolean | 否 | 返回结果是否为纳秒数。<br/>- true:表示返回结果为纳秒数(ns)。 <br/>- false:表示返回结果为毫秒数(ms)。 |
**返回值:**
| 类型 | 说明 |
| --------------------- | --------------------------- |
| Promise&lt;number&gt; | Promise对象,返回自Unix纪元以来经过的时间。 |
**示例:**
```js
try {
systemDateTime.getCurrentTime().then((time) => {
console.info(`Succeeded in getting currentTime : ${time}`);
}).catch((error) => {
console.info(`Failed to get currentTime. message:${error.message}, code:${error.code}`);
});
} catch(e) {
console.info(`Failed to get currentTime. message:${e.message}, code:${e.code}`);
}
```
## systemDateTime.getRealActiveTime
getRealActiveTime(isNano: boolean, callback: AsyncCallback&lt;number&gt;): void
获取自系统启动以来经过的时间,不包括深度睡眠时间,使用callback异步回调。
**系统能力:** SystemCapability.MiscServices.Time
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------- | ---- | -------------------------- |
| isNano | boolean | 是 | 返回结果是否为纳秒数。<br/>- true:表示返回结果为纳秒数(ns)。 <br/>- false:表示返回结果为毫秒数(ms)。 |
| callback | AsyncCallback&lt;number&gt; | 是 | 回调函数,返回自系统启动以来经过的时间,但不包括度睡眠时间。 |
**示例:**
```js
try {
systemDateTime.getRealActiveTime(true, (error, time) => {
if (error) {
console.info(`Failed to get 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}`);
}
```
## systemDateTime.getRealActiveTime
getRealActiveTime(callback: AsyncCallback&lt;number&gt;): void
获取自系统启动以来经过的时间,不包括深度睡眠时间,使用callback异步回调。
**系统能力:** SystemCapability.MiscServices.Time
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------- | ---- | --------------------- |
| callback | AsyncCallback&lt;number&gt; | 是 | 回调函数,返回自系统启动以来经过的时间,但不包括度睡眠时间。 |
**示例:**
```js
try {
systemDateTime.getRealActiveTime((error, time) => {
if (error) {
console.info(`Failed to get 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}`);
}
```
## systemDateTime.getRealActiveTime
getRealActiveTime(isNano?: boolean): Promise&lt;number&gt;
获取自系统启动以来经过的时间,不包括深度睡眠时间,使用Promise异步回调。
**系统能力:** SystemCapability.MiscServices.Time
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------- | ---- | ----------------------------------- |
| isNano | boolean | 否 | 返回结果是否为纳秒数。<br/>- true:表示返回结果为纳秒数(ns)。 <br/>- false:表示返回结果为毫秒数(ms)。 |
**返回值:**
| 类型 | 说明 |
| -------------- | -------------------------------- |
| Promise&lt;number&gt; | Promise对象,返回自系统启动以来经过的时间,但不包括深度睡眠时间。 |
**示例:**
```js
try {
systemDateTime.getRealActiveTime().then((time) => {
console.info(`Succeeded in getting real active time : ${time}`);
}).catch((error) => {
console.info(`Failed to get 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}`);
}
```
## systemDateTime.getRealTime
getRealTime(isNano: boolean, callback: AsyncCallback&lt;number&gt;): void
获取自系统启动以来经过的时间,包括深度睡眠时间,使用callback异步回调。
**系统能力:** SystemCapability.MiscServices.Time
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------- | ---- | ------------------------------- |
| isNano | boolean | 是 | 返回结果是否为纳秒数。<br/>- true:表示返回结果为纳秒数(ns)。 <br/>- false:表示返回结果为毫秒数(ms)。 |
| callback | AsyncCallback&lt;number&gt; | 是 | 回调函数,返回自系统启动以来经过的时间,包括深度睡眠时间。 |
**示例:**
```js
try {
systemDateTime.getRealTime(true, (error, time) => {
if (error) {
console.info(`Failed to get 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}`);
}
```
## systemDateTime.getRealTime
getRealTime(callback: AsyncCallback&lt;number&gt;): void
获取自系统启动以来经过的时间,包括深度睡眠时间,使用callback异步回调。
**系统能力:** SystemCapability.MiscServices.Time
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------- | ---- | --------------------------- |
| callback | AsyncCallback&lt;number&gt; | 是 | 回调函数,返回自系统启动以来经过的时间,包括深度睡眠时间。 |
**示例:**
```js
try {
systemDateTime.getRealTime((error, time) => {
if (error) {
console.info(`Failed to get 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}`);
}
```
## systemDateTime.getRealTime
getRealTime(isNano?: boolean): Promise&lt;number&gt;
获取自系统启动以来经过的时间,包括深度睡眠时间,使用Promise异步回调。
**系统能力:** SystemCapability.MiscServices.Time
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------- | ---- | ------------------------------- |
| isNano | boolean | 否 | 返回结果是否为纳秒数。<br/>- true:表示返回结果为纳秒数(ns)。 <br/>- false:表示返回结果为毫秒数(ms)。 |
**返回值:**
| 类型 | 说明 |
| --------------------- | ------------------------------- |
| Promise&lt;number&gt; | Promise对象,返回自系统启动以来经过的时间,包括深度睡眠时间。 |
**示例:**
```js
try {
systemDateTime.getRealTime().then((time) => {
console.info(`Succeeded in getting real time : ${time}`);
}).catch((error) => {
console.info(`Failed to get real time. message:${error.message}, code:${error.code}`);
});
} catch(e) {
console.info(`Failed to get real time. message:${e.message}, code:${e.code}`);
}
```
## systemDateTime.setDate
setDate(date: Date, callback: AsyncCallback&lt;void&gt;): void
设置系统日期,使用callback异步回调。
**系统接口:** 此接口为系统接口
**系统能力:** SystemCapability.MiscServices.Time
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------- | ---- | --------------------- |
| date | Date | 是 | 目标日期。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。 |
**示例:**
```js
let date = new Date();
try {
systemDateTime.setDate(date, (error) => {
if (error) {
console.info(`Failed to set 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}`);
}
```
## systemDateTime.setDate
setDate(date: Date): Promise&lt;void&gt;
设置系统日期,使用Promise异步回调。
**系统接口:** 此接口为系统接口
**系统能力:** SystemCapability.MiscServices.Time
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ---- | ---- | ---------- |
| date | Date | 是 | 目标日期。 |
**返回值:**
| 类型 | 说明 |
| ------------------- | -------------------- |
| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
**示例:**
```js
let date = new Date();
try {
systemDateTime.setDate(date).then(() => {
console.info(`Succeeded in setting date.`);
}).catch((error) => {
console.info(`Failed to set date. message:${error.message}, code:${error.code}`);
});
} catch(e) {
console.info(`Failed to set date. message:${e.message}, code:${e.code}`);
}
```
## systemDateTime.getDate
getDate(callback: AsyncCallback&lt;Date&gt;): void
获取当前系统日期,使用callback异步回调。
**系统能力:** SystemCapability.MiscServices.Time
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------- | ---- | --------------------- |
| callback | AsyncCallback&lt;Date&gt; | 是 | 回调函数,返回当前系统日期。 |
**示例:**
```js
try {
systemDateTime.getDate((error, date) => {
if (error) {
console.info(`Failed to get date. message:${error.message}, code:${error.code}`);
return;
}
console.info(`Succeeded in getting date : ${date}`);;
});
} catch(e) {
console.info(`Failed to get date. message:${e.message}, code:${e.code}`);
}
```
## systemDateTime.getDate
getDate(): Promise&lt;Date&gt;
获取当前系统日期,使用Promise异步回调。
**系统能力:** SystemCapability.MiscServices.Time
**返回值:**
| 类型 | 说明 |
| ------------------- | ----------------------------------------- |
| Promise&lt;Date&gt; | Promise对象,返回当前系统日期。 |
**示例:**
```js
try {
systemDateTime.getDate().then((date) => {
console.info(`Succeeded in getting date : ${date}`);
}).catch((error) => {
console.info(`Failed to get date. message:${error.message}, code:${error.code}`);
});
} catch(e) {
console.info(`Failed to get date. message:${e.message}, code:${e.code}`);
}
```
## systemDateTime.setTimezone
setTimezone(timezone: string, callback: AsyncCallback&lt;void&gt;): void
设置系统时区,使用callback异步回调。
**系统接口:** 此接口为系统接口
**系统能力:** SystemCapability.MiscServices.Time
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------- | ---- | -------------------------- |
| timezone | string | 是 | 系统时区。 具体可见[支持的系统时区](#支持的系统时区) 。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。 |
**示例:**
```js
try {
systemDateTime.setTimezone('Asia/Shanghai', (error) => {
if (error) {
console.info(`Failed to set 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}`);
}
```
## systemDateTime.setTimezone
setTimezone(timezone: string): Promise&lt;void&gt;
设置系统时区,使用Promise异步回调。
**系统接口:** 此接口为系统接口
**系统能力:** SystemCapability.MiscServices.Time
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------ | ---- | ---------- |
| timezone | string | 是 | 系统时区。具体可见[支持的系统时区](#支持的系统时区) 。 |
**返回值:**
| 类型 | 说明 |
| ------------------- | -------------------- |
| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
**示例:**
```js
try {
systemDateTime.setTimezone('Asia/Shanghai').then(() => {
console.info(`Succeeded in setting timezone.`);
}).catch((error) => {
console.info(`Failed to set timezone. message:${error.message}, code:${error.code}`);
});
} catch(e) {
console.info(`Failed to set timezone. message:${e.message}, code:${e.code}`);
}
```
## systemDateTime.getTimezone
getTimezone(callback: AsyncCallback&lt;string&gt;): void
获取系统时区,使用callback异步回调。
**系统能力:** SystemCapability.MiscServices.Time
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------- | ---- | ------------------------ |
| callback | AsyncCallback&lt;string&gt; | 是 | 回调函数,返回系统时区。具体可见[支持的系统时区](#支持的系统时区) 。 |
**示例:**
```js
try {
systemDateTime.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}`);
}
```
## systemDateTime.getTimezone
getTimezone(): Promise&lt;string&gt;
获取系统时区,使用Promise异步回调。
**系统能力:** SystemCapability.MiscServices.Time
**返回值:**
| 类型 | 说明 |
| --------------------- | ------------------------------------- |
| Promise&lt;string&gt; | Promise对象,返回系统时区。具体可见[支持的系统时区](#支持的系统时区) 。 |
**示例:**
```js
try {
systemDateTime.getTimezone().then((data) => {
console.info(`Succeeded in getting timezone: ${data}`);
}).catch((error) => {
console.info(`Failed to get timezone. message:${error.message}, code:${error.code}`);
});
} catch(e) {
console.info(`Failed to get timezone. message:${e.message}, code:${e.code}`);
}
```
## 支持的系统时区
支持的系统时区及各时区与0时区相比的偏移量(单位:h)可见下表。
| 时区 | 偏移量 |
| ------------------------------ | --------------------- |
| Antarctica/McMurdo | 12 |
| America/Argentina/Buenos_Aires | -3 |
| Australia/Sydney | 10 |
| America/Noronha | -2 |
| America/St_Johns | -3 |
| Africa/Kinshasa | 1 |
| America/Santiago | -3 |
| Asia/Shanghai | 8 |
| Asia/Nicosia | 3 |
| Europe/Berlin | 2 |
| America/Guayaquil | -5 |
| Europe/Madrid | 2 |
| Pacific/Pohnpei | 11 |
| America/Godthab | -2 |
| Asia/Jakarta | 7 |
| Pacific/Tarawa | 12 |
| Asia/Almaty | 6 |
| Pacific/Majuro | 12 |
| Asia/Ulaanbaatar | 8 |
| America/Mexico_City | -5 |
| Asia/Kuala_Lumpur | 8 |
| Pacific/Auckland | 12 |
| Pacific/Tahiti | -10 |
| Pacific/Port_Moresby | 10 |
| Asia/Gaza | 3 |
| Europe/Lisbon | 1 |
| Europe/Moscow | 3 |
| Europe/Kiev | 3 |
| Pacific/Wake | 12 |
| America/New_York | -4 |
| Asia/Tashkent | 5 |
\ No newline at end of file
......@@ -25,7 +25,7 @@ setTime(time : number, callback : AsyncCallback&lt;void&gt;) : void
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------- | ---- | ---------------- |
| -------- | ------------------------- | ---- | ------------------ |
| time | number | 是 | 目标时间戳(ms)。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。 |
......@@ -42,13 +42,17 @@ setTime(time : number, callback : AsyncCallback&lt;void&gt;) : void
```js
// time对应的时间为2021-01-20 02:36:25
let time = 1611081385000;
systemTime.setTime(time, (error, data) => {
try {
systemTime.setTime(time, (error) => {
if (error) {
console.error(`Failed to set systemTime. Cause:` + JSON.stringify(error));
console.info(`Failed to setting time. message: ${error.message}, code: ${error.code}`);
return;
}
console.log(`Succeeded in setting systemTime. Data:` + JSON.stringify(data));
});
}console.info(`Succeeded in setting time`);
});
} catch(e) {
console.info(`Failed to set time. message: ${e.message}, code: ${e.code}`);
}
```
## systemTime.setTime
......@@ -86,11 +90,15 @@ setTime(time : number) : Promise&lt;void&gt;
```js
// time对应的时间为2021-01-20 02:36:25
let time = 1611081385000;
systemTime.setTime(time).then((data) => {
console.log(`Succeeded in setting systemTime. Data:` + JSON.stringify(data));
}).catch((error) => {
console.error(`Failed to set systemTime. Cause:` + JSON.stringify(error));
});
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}`);
});
} catch(e) {
console.info(`Failed to set time. message: ${e.message}, code: ${e.code}`);
}
```
## systemTime.getCurrentTime<sup>8+</sup>
......@@ -104,7 +112,7 @@ getCurrentTime(isNano: boolean, callback: AsyncCallback&lt;number&gt;): void
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------- | ---- | ------------------ |
| -------- | --------------------------- | ---- | ------------------------------------------------------------ |
| isNano | boolean | 是 | 返回结果是否为纳秒数。<br>- true:表示返回结果为纳秒数(ns)。 <br>- false:表示返回结果为毫秒数(ms)。 |
| callback | AsyncCallback&lt;number&gt; | 是 | 回调函数,返回自Unix纪元以来经过的时间。 |
......@@ -119,13 +127,17 @@ getCurrentTime(isNano: boolean, callback: AsyncCallback&lt;number&gt;): void
**示例:**
```js
systemTime.getCurrentTime(true, (error, data) => {
try {
systemTime.getCurrentTime(true, (error, time) => {
if (error) {
console.error(`Failed to get systemTime. Cause:` + JSON.stringify(error));
console.info(`Failed to getting currentTime. message: ${error.message}, code: ${error.code}`);
return;
}
console.log(`Succeeded in getting systemTime. Data:` + JSON.stringify(data));
});
console.info(`Succeeded in getting currentTime: ${time}`);
});
} catch(e) {
console.info(`Failed to get currentTime. message: ${e.message}, code: ${e.code}`);
}
```
## systemTime.getCurrentTime<sup>8+</sup>
......@@ -139,7 +151,7 @@ getCurrentTime(callback: AsyncCallback&lt;number&gt;): void
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------- | ---- | ---------------------------------- |
| -------- | --------------------------- | ---- | ---------------------------------------- |
| callback | AsyncCallback&lt;number&gt; | 是 | 回调函数,返回自Unix纪元以来经过的时间。 |
**错误码:**
......@@ -153,13 +165,17 @@ getCurrentTime(callback: AsyncCallback&lt;number&gt;): void
**示例:**
```js
systemTime.getCurrentTime((error, data) => {
try {
systemTime.getCurrentTime((error, time) => {
if (error) {
console.error(`Succeeded in getting systemTime. Data:` + JSON.stringify(error));
console.info(`Failed to getting currentTime. message: ${error.message}, code: ${error.code}`);
return;
}
console.log(`Failed to get systemTime. Cause:` + JSON.stringify(data));
});
console.info(`Succeeded in getting currentTime : ${time}`);
});
} catch(e) {
console.info(`Failed to get currentTime. message: ${e.message}, code: ${e.code}`);
}
```
## systemTime.getCurrentTime<sup>8+</sup>
......@@ -173,13 +189,13 @@ getCurrentTime(isNano?: boolean): Promise&lt;number&gt;
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------- | ---- | ------------------------- |
| ------ | ------- | ---- | ------------------------------------------------------------ |
| isNano | boolean | 否 | 返回结果是否为纳秒数。<br/>- true:表示返回结果为纳秒数(ns)。 <br/>- false:表示返回结果为毫秒数(ms)。 |
**返回值:**
| 类型 | 说明 |
| --------------------- | --------------------------- |
| --------------------- | ------------------------------------------- |
| Promise&lt;number&gt; | Promise对象,返回自Unix纪元以来经过的时间。 |
**错误码:**
......@@ -193,11 +209,15 @@ getCurrentTime(isNano?: boolean): Promise&lt;number&gt;
**示例:**
```js
systemTime.getCurrentTime().then((data) => {
console.log(`Succeeded in getting systemTime. Data:` + JSON.stringify(data));
}).catch((error) => {
console.error(`Failed to get systemTime. Cause:` + JSON.stringify(error));
});
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}`);
});
} catch(e) {
console.info(`Failed to get currentTime. message: ${e.message}, code: ${e.code}`);
}
```
## systemTime.getRealActiveTime<sup>8+</sup>
......@@ -211,7 +231,7 @@ getRealActiveTime(isNano: boolean, callback: AsyncCallback&lt;number&gt;): void
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------- | ---- | -------------------------- |
| -------- | --------------------------- | ---- | ------------------------------------------------------------ |
| isNano | boolean | 是 | 返回结果是否为纳秒数。<br/>- true:表示返回结果为纳秒数(ns)。 <br/>- false:表示返回结果为毫秒数(ms)。 |
| callback | AsyncCallback&lt;number&gt; | 是 | 回调函数,返回自系统启动以来经过的时间,但不包括度睡眠时间。 |
......@@ -226,13 +246,17 @@ getRealActiveTime(isNano: boolean, callback: AsyncCallback&lt;number&gt;): void
**示例:**
```js
systemTime.getRealActiveTime(true, (error, data) => {
try {
systemTime.getRealActiveTime(true, (error, time) => {
if (error) {
console.error(`Failed to get real active time. Cause:` + JSON.stringify(error));
console.info(`Failed to getting real active time. message: ${error.message}, code: ${error.code}`);
return;
}
console.log(`Succeeded in getting real active time. Data:` + JSON.stringify(data));
});
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}`);
}
```
## systemTime.getRealActiveTime<sup>8+</sup>
......@@ -246,7 +270,7 @@ getRealActiveTime(callback: AsyncCallback&lt;number&gt;): void
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------- | ---- | --------------------- |
| -------- | --------------------------- | ---- | ------------------------------------------------------------ |
| callback | AsyncCallback&lt;number&gt; | 是 | 回调函数,返回自系统启动以来经过的时间,但不包括度睡眠时间。 |
**错误码:**
......@@ -260,13 +284,17 @@ getRealActiveTime(callback: AsyncCallback&lt;number&gt;): void
**示例:**
```js
systemTime.getRealActiveTime((error, data) => {
try {
systemTime.getRealActiveTime((error, time) => {
if (error) {
console.error(`Failed to get real active time. Cause:` + JSON.stringify(error));
console.info(`Failed to getting real active time. message: ${error.message}, code: ${error.code}`);
return;
}
console.log(`Succeeded in getting real active time. Data:` + JSON.stringify(data));
});
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}`);
}
```
## systemTime.getRealActiveTime<sup>8+</sup>
......@@ -280,13 +308,13 @@ getRealActiveTime(isNano?: boolean): Promise&lt;number&gt;
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------- | ---- | ----------------------------------- |
| ------ | ------- | ---- | ------------------------------------------------------------ |
| isNano | boolean | 否 | 返回结果是否为纳秒数。<br/>- true:表示返回结果为纳秒数(ns)。 <br/>- false:表示返回结果为毫秒数(ms)。 |
**返回值:**
| 类型 | 说明 |
| -------------- | -------------------------------- |
| --------------------- | ------------------------------------------------------------ |
| Promise&lt;number&gt; | Promise对象,返回自系统启动以来经过的时间,但不包括深度睡眠时间。 |
**错误码:**
......@@ -300,11 +328,15 @@ getRealActiveTime(isNano?: boolean): Promise&lt;number&gt;
**示例:**
```js
systemTime.getRealActiveTime().then((data) => {
console.log(`Succeeded in getting real active time. Data:` + JSON.stringify(data));
}).catch((error) => {
console.error(`Failed to get real active time. Cause:` + JSON.stringify(error));
});
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}`);
});
} catch(e) {
console.info(`Failed to get real active time. message: ${e.message}, code: ${e.code}`);
}
```
## systemTime.getRealTime<sup>8+</sup>
......@@ -318,7 +350,7 @@ getRealTime(isNano: boolean, callback: AsyncCallback&lt;number&gt;): void
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------- | ---- | ------------------------------- |
| -------- | --------------------------- | ---- | ------------------------------------------------------------ |
| isNano | boolean | 是 | 返回结果是否为纳秒数。<br/>- true:表示返回结果为纳秒数(ns)。 <br/>- false:表示返回结果为毫秒数(ms)。 |
| callback | AsyncCallback&lt;number&gt; | 是 | 回调函数,返回自系统启动以来经过的时间,包括深度睡眠时间。 |
......@@ -333,13 +365,17 @@ getRealTime(isNano: boolean, callback: AsyncCallback&lt;number&gt;): void
**示例:**
```js
systemTime.getRealTime(true, (error, data) => {
try {
systemTime.getRealTime(true, (error, time) => {
if (error) {
console.error(`Failed to get real time. Cause:` + JSON.stringify(error));
console.info(`Failed to getting real time. message: ${error.message}, code: ${error.code}`);
return;
}
console.log(`Succeeded in getting real time. Data:` + JSON.stringify(data));
});
console.info(`Succeeded in getting real time : ${time}`);
});
} catch(e) {
console.info(`Failed to get real time. message: ${e.message}, code: ${e.code}`);
}
```
## systemTime.getRealTime<sup>8+</sup>
......@@ -353,7 +389,7 @@ getRealTime(callback: AsyncCallback&lt;number&gt;): void
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------- | ---- | --------------------------- |
| -------- | --------------------------- | ---- | ---------------------------------------------------------- |
| callback | AsyncCallback&lt;number&gt; | 是 | 回调函数,返回自系统启动以来经过的时间,包括深度睡眠时间。 |
**错误码:**
......@@ -367,13 +403,17 @@ getRealTime(callback: AsyncCallback&lt;number&gt;): void
**示例:**
```js
systemTime.getRealTime((error, data) => {
try {
systemTime.getRealTime((error, time) => {
if (error) {
console.error(`Failed to get real time. Cause:` + JSON.stringify(error));
console.info(`Failed to getting real time. message: ${error.message}, code: ${error.code}`);
return;
}
console.log(`Succeeded in getting real time. Data:` + JSON.stringify(data));
});
console.info(`Succeeded in getting real time : ${time}`);
});
} catch(e) {
console.info(`Failed to get real time. message: ${e.message}, code: ${e.code}`);
}
```
## systemTime.getRealTime<sup>8+</sup>
......@@ -387,13 +427,13 @@ getRealTime(isNano?: boolean): Promise&lt;number&gt;
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------- | ---- | ------------------------------- |
| isNano | boolean | 否 | 返回结果是否为纳秒数。<<br/>- true:表示返回结果为纳秒数(ns)。 <br/>- false:表示返回结果为毫秒数(ms)。 |
| ------ | ------- | ---- | ------------------------------------------------------------ |
| isNano | boolean | 否 | 返回结果是否为纳秒数。<br/>- true:表示返回结果为纳秒数(ns)。 <br/>- false:表示返回结果为毫秒数(ms)。 |
**返回值:**
| 类型 | 说明 |
| --------------------- | ------------------------------- |
| --------------------- | ------------------------------------------------------------ |
| Promise&lt;number&gt; | Promise对象,返回自系统启动以来经过的时间,包括深度睡眠时间。 |
**错误码:**
......@@ -407,11 +447,15 @@ getRealTime(isNano?: boolean): Promise&lt;number&gt;
**示例:**
```js
systemTime.getRealTime().then((data) => {
console.log(`Succeeded in getting real time. Data:` + JSON.stringify(data));
}).catch((error) => {
console.error(`Failed to get real time. Cause:` + JSON.stringify(error));
});
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}`);
});
} catch(e) {
console.info(`Failed to get real time. message: ${e.message}, code: ${e.code}`);
}
```
## systemTime.setDate
......@@ -427,7 +471,7 @@ setDate(date: Date, callback: AsyncCallback&lt;void&gt;): void
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------- | ---- | --------------------- |
| -------- | ------------------------- | ---- | ---------- |
| date | Date | 是 | 目标日期。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。 |
......@@ -442,14 +486,18 @@ setDate(date: Date, callback: AsyncCallback&lt;void&gt;): void
**示例:**
```js
let data = new Date();
systemTime.setDate(data,(error, data) => {
let date = new Date();
try {
systemTime.setDate(date, (error) => {
if (error) {
console.error('Failed to set system date. Cause:' + JSON.stringify(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('Succeeded in setting system date. Data:' + JSON.stringify(data));
});
```
## systemTime.setDate
......@@ -471,7 +519,7 @@ setDate(date: Date): Promise&lt;void&gt;
**返回值:**
| 类型 | 说明 |
| ------------------- | -------------------- |
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
**错误码:**
......@@ -485,12 +533,16 @@ setDate(date: Date): Promise&lt;void&gt;
**示例:**
```js
let data = new Date();
systemTime.setDate(data).then((value) => {
console.log(`Succeeded in setting system date. Data:` + JSON.stringify(value));
}).catch((error) => {
console.error(`Failed to set system date. Cause:` + JSON.stringify(error));
});
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}`);
});
} catch(e) {
console.info(`Failed to set date. message: ${e.message}, code: ${e.code}`);
}
```
## systemTime.getDate<sup>8+</sup>
......@@ -504,7 +556,7 @@ getDate(callback: AsyncCallback&lt;Date&gt;): void
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------- | ---- | --------------------- |
| -------- | ------------------------- | ---- | ---------------------------- |
| callback | AsyncCallback&lt;Date&gt; | 是 | 回调函数,返回当前系统日期。 |
**错误码:**
......@@ -518,13 +570,17 @@ getDate(callback: AsyncCallback&lt;Date&gt;): void
**示例:**
```js
systemTime.getDate((error, data) => {
try {
systemTime.getDate((error, date) => {
if (error) {
console.error(`Failed to get system date. Cause:` + JSON.stringify(error));
console.info(`Failed to get date. message: ${error.message}, code: ${error.code}`);
return;
}
console.log(`Succeeded in getting system date. Data:` + JSON.stringify(data));
});
console.info(`Succeeded in get date : ${date}`);;
});
} catch(e) {
console.info(`Failed to get date. message: ${e.message}, code: ${e.code}`);
}
```
## systemTime.getDate<sup>8+</sup>
......@@ -538,17 +594,29 @@ getDate(): Promise&lt;Date&gt;
**返回值:**
| 类型 | 说明 |
| ------------------- | ----------------------------------------- |
| ------------------- | ------------------------------- |
| Promise&lt;Date&gt; | Promise对象,返回当前系统日期。 |
**错误码:**
以下错误码的详细介绍请参见[时间时区错误码](../errorcodes/errorcode-time.md)
| 错误码ID | 错误信息 |
| -------- | ------------------------------------------- |
| -1 | The parameter check failed or system error. |
**示例:**
```js
systemTime.getDate().then((data) => {
console.log(`Succeeded in getting system date. Data:` + JSON.stringify(data));
}).catch((error) => {
console.error(`Failed to get system date. Cause:` + JSON.stringify(error));
});
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}`);
});
} catch(e) {
console.info(`Failed to get date. message: ${e.message}, code: ${e.code}`);
}
```
## systemTime.setTimezone
......@@ -564,7 +632,7 @@ setTimezone(timezone: string, callback: AsyncCallback&lt;void&gt;): void
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------- | ---- | -------------------------- |
| -------- | ------------------------- | ---- | ------------------------------------------------------- |
| timezone | string | 是 | 系统时区。 具体可见[支持的系统时区](#支持的系统时区) 。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。 |
......@@ -579,13 +647,17 @@ setTimezone(timezone: string, callback: AsyncCallback&lt;void&gt;): void
**示例:**
```js
systemTime.setTimezone('Asia/Shanghai', (error, data) => {
try {
systemTime.setTimezone('Asia/Shanghai', (error) => {
if (error) {
console.error('Failed to set system time zone. Cause:' + JSON.stringify(error));
console.info(`Failed to setting timezone. message: ${error.message}, code: ${error.code}`);
return;
}
console.info('Succeeded in setting system time zone. Data:' + JSON.stringify(data));
});
console.info(`Succeeded in setting timezone.`);
});
} catch(e) {
console.info(`Failed to set timezone. message: ${e.message}, code: ${e.code}`);
}
```
## systemTime.setTimezone
......@@ -601,13 +673,13 @@ setTimezone(timezone: string): Promise&lt;void&gt;
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------ | ---- | ---------- |
| -------- | ------ | ---- | ------------------------------------------------------ |
| timezone | string | 是 | 系统时区。具体可见[支持的系统时区](#支持的系统时区) 。 |
**返回值:**
| 类型 | 说明 |
| ------------------- | -------------------- |
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
**错误码:**
......@@ -621,11 +693,15 @@ setTimezone(timezone: string): Promise&lt;void&gt;
**示例:**
```js
systemTime.setTimezone('Asia/Shanghai').then((data) => {
console.log(`Succeeded in setting system time zone. Data:` + JSON.stringify(data));
}).catch((error) => {
console.error(`Failed to set system time zone. Cause:` + JSON.stringify(error));
});
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}`);
});
} catch(e) {
console.info(`Failed to set timezone. message: ${e.message}, code: ${e.code}`);
}
```
## systemTime.getTimezone<sup>8+</sup>
......@@ -639,7 +715,7 @@ getTimezone(callback: AsyncCallback&lt;string&gt;): void
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------- | ---- | ------------------------ |
| -------- | --------------------------- | ---- | ------------------------------------------------------------ |
| callback | AsyncCallback&lt;string&gt; | 是 | 回调函数,返回系统时区。具体可见[支持的系统时区](#支持的系统时区) 。 |
**错误码:**
......@@ -653,13 +729,17 @@ getTimezone(callback: AsyncCallback&lt;string&gt;): void
**示例:**
```js
systemTime.getTimezone((error, data) => {
try {
systemTime.getTimezone((error, data) => {
if (error) {
console.error(`Failed to get system time zone. Cause:` + JSON.stringify(error));
console.info(`Failed to get timezone. message: ${error.message}, code: ${error.code}`);
return;
}
console.log(`Succeeded in getting system time zone. Data:` + JSON.stringify(data));
});
console.info(`Succeeded in get timezone : ${data}`);;
});
} catch(e) {
console.info(`Failed to get timezone. message: ${e.message}, code: ${e.code}`);
}
```
## systemTime.getTimezone<sup>8+</sup>
......@@ -673,7 +753,7 @@ getTimezone(): Promise&lt;string&gt;
**返回值:**
| 类型 | 说明 |
| --------------------- | ------------------------------------- |
| --------------------- | ------------------------------------------------------------ |
| Promise&lt;string&gt; | Promise对象,返回系统时区。具体可见[支持的系统时区](#支持的系统时区) 。 |
**错误码:**
......@@ -687,11 +767,15 @@ getTimezone(): Promise&lt;string&gt;
**示例:**
```js
systemTime.getTimezone().then((data) => {
console.log(`Succeeded in getting system time zone. Data:` + JSON.stringify(data));
}).catch((error) => {
console.error(`Failed to get system time zone. Cause:` + JSON.stringify(error));
});
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}`);
});
} catch(e) {
console.info(`Failed to get timezone. message: ${e.message}, code: ${e.code}`);
}
```
## 支持的系统时区
......@@ -699,7 +783,7 @@ systemTime.getTimezone().then((data) => {
支持的系统时区及各时区与0时区相比的偏移量(单位:h)可见下表。
| 时区 | 偏移量 |
| ------------------------------ | --------------------- |
| ------------------------------ | ------ |
| Antarctica/McMurdo | 12 |
| America/Argentina/Buenos_Aires | -3 |
| Australia/Sydney | 10 |
......
......@@ -21,7 +21,7 @@ import systemTimer from '@ohos.systemTimer';
**系统能力:** SystemCapability.MiscServices.Time
| 名称 | 类型 | 值 | 说明 |
| ------------------- | ------ | ---- | ---------------------------- |
| ------------------- | ------ | ---- | ------------------------------------------------------------ |
| TIMER_TYPE_REALTIME | number | 1 | 系统启动时间定时器。(定时器启动时间不能晚于当前设置的系统时间) |
| TIMER_TYPE_WAKEUP | number | 2 | 唤醒定时器。 |
| TIMER_TYPE_EXACT | number | 4 | 精准定时器。 |
......@@ -34,11 +34,11 @@ import systemTimer from '@ohos.systemTimer';
**系统能力:** SystemCapability.MiscServices.Time
| 名称 | 类型 | 必填 | 说明 |
| --------- | --------------------------------- | ---- | ------------------------------------------------------------ |
| type | number | 是 | 定时器类型。<br>取值为1时,表示为系统启动时间定时器(定时器启动时间不能晚于当前设置的系统时间) ;<br>取值为2时,表示为唤醒定时器;<br>取值为4时,表示为精准定时器;<br>取值为5时,表示为IDLE模式定时器(暂不支持)。 |
| --------- | --------------------------------------------- | ---- | ------------------------------------------------------------ |
| type | number | 是 | 定时器类型。<br>取值为1,表示为系统启动时间定时器(定时器启动时间不能晚于当前设置的系统时间) ;<br>取值为2,表示为唤醒定时器;<br>取值为4,表示为精准定时器;<br>取值为8,表示为IDLE模式定时器(暂不支持)。 |
| repeat | boolean | 是 | true为循环定时器,false为单次定时器。 |
| interval | number | 否 | 如果是循环定时器,repeat值应大于5000毫秒,非重复定时器置为0。 |
| wantAgent | [WantAgent](js-apis-wantAgent.md) | 否 | 设置通知的WantAgent,定时器到期后通知。(支持拉起应用MainAbility,暂不支持拉起ServiceAbility。) |
| wantAgent | [WantAgent](js-apis-app-ability-wantAgent.md) | 否 | 设置通知的WantAgent,定时器到期后通知。(支持拉起应用MainAbility,暂不支持拉起ServiceAbility。) |
| callback | number | 是 | 以回调函数的形式返回定时器的ID。 |
......@@ -66,13 +66,17 @@ export default {
type: systemTimer.TIMER_TYPE_REALTIME,
repeat: false
};
systemTimer.createTimer(options, (error, data) => {
try {
systemTimer.createTimer(options, (error, timerId) => {
if (error) {
console.error(`Failed to create timer. Cause:` + JSON.stringify(error));
console.info(`Failed to create timer. message: ${error.message}, code: ${error.code}`);
return;
}
console.log(`Succeeded in creating timer. Data:` + JSON.stringify(data));
console.info(`Succeeded in creating timer. timerId: ${timerId}`);
});
} catch(e) {
console.info(`Failed to create timer. message: ${e.message}, code: ${e.code}`);
}
}
}
```
......@@ -106,11 +110,15 @@ export default {
type: systemTimer.TIMER_TYPE_REALTIME,
repeat:false
};
systemTimer.createTimer(options).then((data) => {
console.log(`Succeeded in creating timer. Data:` + JSON.stringify(data));
try {
systemTimer.createTimer(options).then((timerId) => {
console.info(`Succeeded in creating timer. timerId: ${timerId}`);
}).catch((error) => {
console.error(`Failed to create timer. Cause:` + JSON.stringify(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}`);
}
}
}
```
......@@ -140,15 +148,20 @@ export default {
type: systemTimer.TIMER_TYPE_REALTIME,
repeat:false
}
let timerId = await systemTimer.createTimer(options)
let triggerTime = new Date().getTime()
triggerTime += 3000
let timerId = await systemTimer.createTimer(options);
let triggerTime = new Date().getTime();
triggerTime += 3000;
try {
systemTimer.startTimer(timerId, triggerTime, (error) => {
if (error) {
console.error(`Failed to start timer. Cause:` + JSON.stringify(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}`);
}
}
}
```
......@@ -183,14 +196,18 @@ export default {
type: systemTimer.TIMER_TYPE_REALTIME,
repeat:false
}
let timerId = await systemTimer.createTimer(options)
let triggerTime = new Date().getTime()
triggerTime += 3000
systemTimer.startTimer(timerId, triggerTime).then((data) => {
console.log(`Succeeded in startting timer. Data:` + JSON.stringify(data));
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.error(`Failed to start timer. Cause:` + JSON.stringify(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}`);
}
}
}
```
......@@ -219,16 +236,21 @@ export default {
type: systemTimer.TIMER_TYPE_REALTIME,
repeat:false
}
let timerId = await systemTimer.createTimer(options)
let triggerTime = new Date().getTime()
triggerTime += 3000
systemTimer.startTimer(timerId, triggerTime)
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.error(`Failed to stop timer. Cause:` + JSON.stringify(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}`);
}
}
}
```
......@@ -262,15 +284,19 @@ export default {
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).then((data) => {
console.log(`Succeeded in stopping timer. Data:` + JSON.stringify(data));
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.error(`Failed to stop timer. Cause:` + JSON.stringify(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}`);
}
}
}
```
......@@ -299,17 +325,22 @@ export default {
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)
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.error(`Failed to destroy timer. Cause:` + JSON.stringify(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}`);
}
}
}
```
......@@ -343,16 +374,20 @@ export default {
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)
systemTimer.destroyTimer(timerId).then((data) => {
console.log(`Succeeded in destroying timer. Data:` + JSON.stringify(data));
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.error(`Failed to destroy timer. Cause:` + JSON.stringify(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}`);
}
}
}
```
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册