未验证 提交 74523f77 编写于 作者: 葛亚芳 提交者: Gitee

update zh-cn/application-dev/reference/apis/js-apis-system-time.md.

Signed-off-by: N葛亚芳 <geyafang@huawei.com>
上级 15c7d120
...@@ -2,22 +2,21 @@ ...@@ -2,22 +2,21 @@
本模块主要由系统时间和系统时区功能组成。开发者可以设置、获取系统时间及系统时区。 本模块主要由系统时间和系统时区功能组成。开发者可以设置、获取系统时间及系统时区。
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:** > **说明:**
>- 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 >
> 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
## 导入模块 ## 导入模块
```js
```
import systemTime from '@ohos.systemTime'; import systemTime from '@ohos.systemTime';
``` ```
## systemTime.setTime ## systemTime.setTime
setTime(time : number, callback : AsyncCallback&lt;void&gt;) : void setTime(time : number, callback : AsyncCallback&lt;void&gt;) : void
设置系统时间。 设置系统时间,使用callback异步回调
**需要权限:** ohos.permission.SET_TIME **需要权限:** ohos.permission.SET_TIME
...@@ -25,31 +24,30 @@ setTime(time : number, callback : AsyncCallback&lt;void&gt;) : void ...@@ -25,31 +24,30 @@ setTime(time : number, callback : AsyncCallback&lt;void&gt;) : void
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------- | ---- | ------------------------------------------ | | -------- | ----------- | ---- | ---------------- |
| time | number | 是 | 目标时间戳(ms)。 | | time | number | 是 | 目标时间戳(ms)。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数,可以在回调函数中处理接口返回值。 | | callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。 |
**示例:** **示例:**
```js ```js
// time对应的时间为2021-01-20 02:36:25 // time对应的时间为2021-01-20 02:36:25
var time = 1611081385000; let time = 1611081385000;
systemTime.setTime(time, (error, data) => { systemTime.setTime(time, (error, data) => {
if (error) { if (error) {
console.error(`failed to systemTime.setTime because ` + JSON.stringify(error)); console.error(`Failed to set systemTime. Cause:` + JSON.stringify(error));
return; return;
} }
console.log(`systemTime.setTime success data : ` + JSON.stringify(data)); console.log(`Succeeded in setting systemTime. Data:` + JSON.stringify(data));
}); });
``` ```
## systemTime.setTime ## systemTime.setTime
setTime(time : number) : Promise&lt;void&gt; setTime(time : number) : Promise&lt;void&gt;
设置系统时间。 设置系统时间,使用Promise异步回调
**需要权限:** ohos.permission.SET_TIME **需要权限:** ohos.permission.SET_TIME
...@@ -63,285 +61,276 @@ setTime(time : number) : Promise&lt;void&gt; ...@@ -63,285 +61,276 @@ setTime(time : number) : Promise&lt;void&gt;
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| ------------------- | -------------------- | | ------------------- | ------------------------- |
| Promise&lt;void&gt; | 返回的异步回调函数。 | | Promise&lt;void&gt; | 无返回结果的Promise对象。 |
**示例:** **示例:**
```js ```js
// time对应的时间为2021-01-20 02:36:25 // time对应的时间为2021-01-20 02:36:25
var time = 1611081385000; let time = 1611081385000;
systemTime.setTime(time).then((data) => { systemTime.setTime(time).then((data) => {
console.log(`systemTime.setTime success data : ` + JSON.stringify(data)); console.log(`Succeeded in setting systemTime. Data:` + JSON.stringify(data));
}).catch((error) => { }).catch((error) => {
console.error(`failed to systemTime.setTime because ` + JSON.stringify(error)); console.error(`Failed to set systemTime. Cause:` + JSON.stringify(error));
}); });
``` ```
## systemTime.getCurrentTime<sup>8+</sup> ## systemTime.getCurrentTime<sup>8+</sup>
getCurrentTime(isNano: boolean, callback: AsyncCallback&lt;number&gt;): void getCurrentTime(isNano: boolean, callback: AsyncCallback&lt;number&gt;): void
获取自 Unix 纪元以来经过的时间,使用callback形式返回结果 获取自Unix纪元以来经过的时间,使用callback异步回调
**系统能力:** SystemCapability.MiscServices.Time **系统能力:** SystemCapability.MiscServices.Time
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------- | ---- | ------------------------------------------------------------ | | -------- | -------------- | ---- | ------------------ |
| isNano | boolean | 是 | 返回结果是否为纳秒数。 - true:纳秒数。 <br>- false:毫秒数。 <br> | | isNano | boolean | 是 | 返回结果是否为纳秒数。<br>- true:表示返回结果为纳秒数(ns)。 <br>- false:表示返回结果为毫秒数(ms)。 |
| callback | AsyncCallback&lt;number&gt; | 是 | 回调函数,返回自&nbsp;Unix&nbsp;纪元以来经过的时间。 | | callback | AsyncCallback&lt;number&gt; | 是 | 回调函数,返回自Unix纪元以来经过的时间。 |
**示例:** **示例:**
```js ```js
systemTime.getCurrentTime(true, (error, data) => { systemTime.getCurrentTime(true, (error, data) => {
if (error) { if (error) {
console.error(`failed to systemTime.getCurrentTime because ` + JSON.stringify(error)); console.error(`Failed to get systemTime. Cause:` + JSON.stringify(error));
return; return;
} }
console.log(`systemTime.getCurrentTime success data : ` + JSON.stringify(data)); console.log(`Succeeded in getting systemTime. Data:` + JSON.stringify(data));
}); });
``` ```
## systemTime.getCurrentTime<sup>8+</sup> ## systemTime.getCurrentTime<sup>8+</sup>
getCurrentTime(callback: AsyncCallback&lt;number&gt;): void getCurrentTime(callback: AsyncCallback&lt;number&gt;): void
获取自 Unix 纪元以来经过的时间,使用callback形式返回结果 获取自Unix纪元以来经过的时间,使用callback异步回调
**系统能力:** SystemCapability.MiscServices.Time **系统能力:** SystemCapability.MiscServices.Time
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------- | ---- | ------------------------------------------------------------ | | -------- | ----------- | ---- | ---------------------------------- |
| callback | AsyncCallback&lt;number&gt; | 是 | 回调函数,返回自&nbsp;Unix&nbsp;纪元以来经过的时间。 | | callback | AsyncCallback&lt;number&gt; | 是 | 回调函数,返回自Unix纪元以来经过的时间。 |
**示例:** **示例:**
```js ```js
systemTime.getCurrentTime((error, data) => { systemTime.getCurrentTime((error, data) => {
if (error) { if (error) {
console.error(`failed to systemTime.getCurrentTime because ` + JSON.stringify(error)); console.error(`Succeeded in getting systemTime. Data:` + JSON.stringify(error));
return; return;
} }
console.log(`systemTime.getCurrentTime success data : ` + JSON.stringify(data)); console.log(`Failed to get systemTime. Cause:` + JSON.stringify(data));
}); });
``` ```
## systemTime.getCurrentTime<sup>8+</sup> ## systemTime.getCurrentTime<sup>8+</sup>
getCurrentTime(isNano?: boolean): Promise&lt;number&gt; getCurrentTime(isNano?: boolean): Promise&lt;number&gt;
获取自 Unix 纪元以来经过的时间,使用Promise形式返回结果 获取自Unix纪元以来经过的时间,使用Promise异步回调
**系统能力:** SystemCapability.MiscServices.Time **系统能力:** SystemCapability.MiscServices.Time
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| ------ | ------- | ---- | ------------------------------------------------------------ | | ------ | ------- | ---- | ------------------------- |
| isNano | boolean | 否 | 返回结果是否为纳秒数。 - true:纳秒数。 <br>- false:毫秒数。 <br> | | isNano | boolean | 否 | 返回结果是否为纳秒数。<br/>- true:表示返回结果为纳秒数(ns)。 <br/>- false:表示返回结果为毫秒数(ms)。 |
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| --------------------- | ------------------------------------------------------------ | | --------------------- | --------------------------- |
| Promise&lt;number&gt; | 以Promise形式返回结果,返回自&nbsp;Unix&nbsp;纪元以来经过的时间。 | | Promise&lt;number&gt; | Promise对象,返回自Unix纪元以来经过的时间。 |
**示例:** **示例:**
```js ```js
systemTime.getCurrentTime().then((data) => { systemTime.getCurrentTime().then((data) => {
console.log(`systemTime.getCurrentTime success data : ` + JSON.stringify(data)); console.log(`Succeeded in getting systemTime. Data:` + JSON.stringify(data));
}).catch((error) => { }).catch((error) => {
console.error(`failed to systemTime.getCurrentTime because ` + JSON.stringify(error)); console.error(`Failed to get systemTime. Cause:` + JSON.stringify(error));
}); });
``` ```
## systemTime.getRealActiveTime<sup>8+</sup> ## systemTime.getRealActiveTime<sup>8+</sup>
getRealActiveTime(isNano: boolean, callback: AsyncCallback&lt;number&gt;): void getRealActiveTime(isNano: boolean, callback: AsyncCallback&lt;number&gt;): void
获取自系统启动以来经过的时间,不包括深度睡眠时间,使用callback形式返回结果 获取自系统启动以来经过的时间,不包括深度睡眠时间,使用callback异步回调
**系统能力:** SystemCapability.MiscServices.Time **系统能力:** SystemCapability.MiscServices.Time
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------- | ---- | ------------------------------------------------------------ | | -------- | ---------- | ---- | -------------------------- |
| isNano | boolean | 是 | 返回结果是否为纳秒数。 - true:纳秒数。 <br>- false:毫秒数。 <br> | | isNano | boolean | 是 | 返回结果是否为纳秒数。<br/>- true:表示返回结果为纳秒数(ns)。 <br/>- false:表示返回结果为毫秒数(ms)。 |
| callback | AsyncCallback&lt;number&gt; | 是 | 回调函数,返回自系统启动以来经过的时间,但不包括度睡眠时间。 | | callback | AsyncCallback&lt;number&gt; | 是 | 回调函数,返回自系统启动以来经过的时间,但不包括度睡眠时间。 |
**示例:** **示例:**
```js ```js
systemTime.getRealActiveTime(true, (error, data) => { systemTime.getRealActiveTime(true, (error, data) => {
if (error) { if (error) {
console.error(`failed to systemTime.getRealActiveTimebecause ` + JSON.stringify(error)); console.error(`Failed to get real active time. Cause:` + JSON.stringify(error));
return; return;
} }
console.log(`systemTime.getRealActiveTime success data : ` + JSON.stringify(data)); console.log(`Succeeded in getting real active time. Data:` + JSON.stringify(data));
}); });
``` ```
## systemTime.getRealActiveTime<sup>8+</sup> ## systemTime.getRealActiveTime<sup>8+</sup>
getRealActiveTime(callback: AsyncCallback&lt;number&gt;): void getRealActiveTime(callback: AsyncCallback&lt;number&gt;): void
获取自系统启动以来经过的时间,不包括深度睡眠时间,使用callback形式返回结果 获取自系统启动以来经过的时间,不包括深度睡眠时间,使用callback异步回调
**系统能力:** SystemCapability.MiscServices.Time **系统能力:** SystemCapability.MiscServices.Time
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------- | ---- | ------------------------------------------------------------ | | -------- | -------------- | ---- | --------------------- |
| callback | AsyncCallback&lt;number&gt; | 是 | 回调函数,返回自系统启动以来经过的时间,但不包括度睡眠时间。 | | callback | AsyncCallback&lt;number&gt; | 是 | 回调函数,返回自系统启动以来经过的时间,但不包括度睡眠时间。 |
**示例:** **示例:**
```js ```js
systemTime.getRealActiveTime((error, data) => { systemTime.getRealActiveTime((error, data) => {
if (error) { if (error) {
console.error(`failed to systemTime.getRealActiveTimebecause ` + JSON.stringify(error)); console.error(`Failed to get real active time. Cause:` + JSON.stringify(error));
return; return;
} }
console.log(`systemTime.getRealActiveTime success data : ` + JSON.stringify(data)); console.log(`Succeeded in getting real active time. Data:` + JSON.stringify(data));
}); });
``` ```
## systemTime.getRealActiveTime<sup>8+</sup> ## systemTime.getRealActiveTime<sup>8+</sup>
getRealActiveTime(isNano?: boolean): Promise&lt;number&gt; getRealActiveTime(isNano?: boolean): Promise&lt;number&gt;
获取自系统启动以来经过的时间,不包括深度睡眠时间,使用Promise形式返回结果 获取自系统启动以来经过的时间,不包括深度睡眠时间,使用Promise异步回调
**系统能力:** SystemCapability.MiscServices.Time **系统能力:** SystemCapability.MiscServices.Time
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| ------ | ------- | ---- | ------------------------------------------------------------ | | ------ | ------- | ---- | ----------------------------------- |
| isNano | boolean | 否 | 返回结果是否为纳秒数。 - true:纳秒数。 <br>- false:毫秒数。 <br> | | isNano | boolean | 否 | 返回结果是否为纳秒数。<br/>- true:表示返回结果为纳秒数(ns)。 <br/>- false:表示返回结果为毫秒数(ms)。 |
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| --------------------- | ------------------------------------------------------------ | | -------------- | -------------------------------- |
| Promise&lt;number&gt; | 以Promise形式返回结果,返回自系统启动以来经过的时间,但不包括深度睡眠时间。 | | Promise&lt;number&gt; | Promise对象,返回自系统启动以来经过的时间,但不包括深度睡眠时间。 |
**示例:** **示例:**
```js ```js
systemTime.getRealActiveTime().then((data) => { systemTime.getRealActiveTime().then((data) => {
console.log(`systemTime.getRealActiveTime success data : ` + JSON.stringify(data)); console.log(`Succeeded in getting real active time. Data:` + JSON.stringify(data));
}).catch((error) => { }).catch((error) => {
console.error(`failed to systemTime.getRealActiveTime because ` + JSON.stringify(error)); console.error(`Failed to get real active time. Cause:` + JSON.stringify(error));
}); });
``` ```
## systemTime.getRealTime<sup>8+</sup> ## systemTime.getRealTime<sup>8+</sup>
getRealTime(isNano: boolean, callback: AsyncCallback&lt;number&gt;): void getRealTime(isNano: boolean, callback: AsyncCallback&lt;number&gt;): void
获取自系统启动以来经过的时间,包括深度睡眠时间,使用callback形式返回结果 获取自系统启动以来经过的时间,包括深度睡眠时间,使用callback异步回调
**系统能力:** SystemCapability.MiscServices.Time **系统能力:** SystemCapability.MiscServices.Time
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------- | ---- | ------------------------------------------------------------ | | -------- | --------------- | ---- | ------------------------------- |
| isNano | boolean | 是 | 返回结果是否为纳秒数。 - true:纳秒数。 <br>- false:毫秒数。 <br> | | isNano | boolean | 是 | 返回结果是否为纳秒数。<br/>- true:表示返回结果为纳秒数(ns)。 <br/>- false:表示返回结果为毫秒数(ms)。 |
| callback | AsyncCallback&lt;number&gt; | 是 | 回调函数,返回自系统启动以来经过的时间,包括深度睡眠时间。 | | callback | AsyncCallback&lt;number&gt; | 是 | 回调函数,返回自系统启动以来经过的时间,包括深度睡眠时间。 |
**示例:** **示例:**
```js ```js
systemTime.getRealTime(true, (error, data) => { systemTime.getRealTime(true, (error, data) => {
if (error) { if (error) {
console.error(`failed to systemTime.getRealTime because ` + JSON.stringify(error)); console.error(`Failed to get real time. Cause:` + JSON.stringify(error));
return; return;
} }
console.log(`systemTime.getRealTime success data: ` + JSON.stringify(data)); console.log(`Succeeded in getting real time. Data:` + JSON.stringify(data));
}); });
``` ```
## systemTime.getRealTime<sup>8+</sup> ## systemTime.getRealTime<sup>8+</sup>
getRealTime(callback: AsyncCallback&lt;number&gt;): void getRealTime(callback: AsyncCallback&lt;number&gt;): void
获取自系统启动以来经过的时间,包括深度睡眠时间,使用callback形式返回结果 获取自系统启动以来经过的时间,包括深度睡眠时间,使用callback异步回调
**系统能力:** SystemCapability.MiscServices.Time **系统能力:** SystemCapability.MiscServices.Time
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------- | ---- | ------------------------------------------------------------ | | -------- | --------- | ---- | --------------------------- |
| callback | AsyncCallback&lt;number&gt; | 是 | 回调函数,返回自系统启动以来经过的时间,包括深度睡眠时间。 | | callback | AsyncCallback&lt;number&gt; | 是 | 回调函数,返回自系统启动以来经过的时间,包括深度睡眠时间。 |
**示例:** **示例:**
```js ```js
systemTime.getRealTime((error, data) => { systemTime.getRealTime((error, data) => {
if (error) { if (error) {
console.error(`failed to systemTime.getRealTime because ` + JSON.stringify(error)); console.error(`Failed to get real time. Cause:` + JSON.stringify(error));
return; return;
} }
console.log(`systemTime.getRealTime success data: ` + JSON.stringify(data)); console.log(`Succeeded in getting real time. Data:` + JSON.stringify(data));
}); });
``` ```
## systemTime.getRealTime<sup>8+</sup> ## systemTime.getRealTime<sup>8+</sup>
getRealTime(isNano?: boolean): Promise&lt;number&gt; getRealTime(isNano?: boolean): Promise&lt;number&gt;
获取自系统启动以来经过的时间,包括深度睡眠时间,使用Promise形式返回结果 获取自系统启动以来经过的时间,包括深度睡眠时间,使用Promise异步回调
**系统能力:** SystemCapability.MiscServices.Time **系统能力:** SystemCapability.MiscServices.Time
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| ------ | ------- | ---- | ------------------------------------------------------------ | | ------ | ------- | ---- | ------------------------------- |
| isNano | boolean | 否 | 返回结果是否为纳秒数。 - true:纳秒数。 <br>- false:毫秒数。 <br> | | isNano | boolean | 否 | 返回结果是否为纳秒数。<<br/>- true:表示返回结果为纳秒数(ns)。 <br/>- false:表示返回结果为毫秒数(ms)。 |
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| --------------------- | ------------------------------------------------------------ | | --------------------- | ------------------------------- |
| Promise&lt;number&gt; | 以Promise形式返回结果,返回自系统启动以来经过的时间,包括深度睡眠时间。 | | Promise&lt;number&gt; | Promise对象,返回自系统启动以来经过的时间,包括深度睡眠时间。 |
**示例:** **示例:**
```js ```js
systemTime.getRealTime().then((data) => { systemTime.getRealTime().then((data) => {
console.log(`systemTime.getRealTime success data: ` + JSON.stringify(data)); console.log(`Succeeded in getting real time. Data:` + JSON.stringify(data));
}).catch((error) => { }).catch((error) => {
console.error(`failed to systemTime.getRealTime because ` + JSON.stringify(error)); console.error(`Failed to get real time. Cause:` + JSON.stringify(error));
}); });
``` ```
## systemTime.setDate ## systemTime.setDate
setDate(date: Date, callback: AsyncCallback&lt;void&gt;): void setDate(date: Date, callback: AsyncCallback&lt;void&gt;): void
设置系统日期,使用callback形式返回结果 设置系统日期,使用callback异步回调
**需要权限:** ohos.permission.SET_TIME **需要权限:** ohos.permission.SET_TIME
...@@ -349,30 +338,29 @@ setDate(date: Date, callback: AsyncCallback&lt;void&gt;): void ...@@ -349,30 +338,29 @@ setDate(date: Date, callback: AsyncCallback&lt;void&gt;): void
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------- | ---- | ------------------------------------------ | | -------- | ------------- | ---- | --------------------- |
| date | Date | 是 | 目标日期。 | | date | Date | 是 | 目标日期。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数,可以在回调函数中处理接口返回值。 | | callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。 |
**示例:** **示例:**
```js ```js
var data = new Date(); let data = new Date();
systemTime.setDate(data,(error, data) => { systemTime.setDate(data,(error, data) => {
if (error) { if (error) {
console.error('failed to systemTime.setDate because ' + JSON.stringify(error)); console.error('Failed to set system date. Cause:' + JSON.stringify(error));
return; return;
} }
console.info('systemTime.setDate success data : ' + JSON.stringify(data)); console.info('Succeeded in setting system date. Data:' + JSON.stringify(data));
}); });
``` ```
## systemTime.setDate ## systemTime.setDate
setDate(date: Date): Promise&lt;void&gt; setDate(date: Date): Promise&lt;void&gt;
设置系统日期,使用Promise形式返回结果 设置系统日期,使用Promise异步回调
**需要权限:** ohos.permission.SET_TIME **需要权限:** ohos.permission.SET_TIME
...@@ -388,52 +376,50 @@ setDate(date: Date): Promise&lt;void&gt; ...@@ -388,52 +376,50 @@ setDate(date: Date): Promise&lt;void&gt;
| 类型 | 说明 | | 类型 | 说明 |
| ------------------- | -------------------- | | ------------------- | -------------------- |
| Promise&lt;void&gt; | 返回的异步回调函数。 | | Promise&lt;void&gt; | 无返回结果的Promise对象。 |
**示例:** **示例:**
```js ```js
var data = new Date(); let data = new Date();
systemTime.setDate(data).then((value) => { systemTime.setDate(data).then((value) => {
console.log(`systemTime.setDate success data : ` + JSON.stringify(value)); console.log(`Succeeded in setting system date. Data:` + JSON.stringify(value));
}).catch((error) => { }).catch((error) => {
console.error(`failed to systemTime.setDate because: ` + JSON.stringify(error)); console.error(`Failed to set system date. Cause:` + JSON.stringify(error));
}); });
``` ```
## systemTime.getDate<sup>8+</sup> ## systemTime.getDate<sup>8+</sup>
getDate(callback: AsyncCallback&lt;Date&gt;): void getDate(callback: AsyncCallback&lt;Date&gt;): void
获取当前系统日期,使用callback形式返回结果 获取当前系统日期,使用callback异步回调
**系统能力:** SystemCapability.MiscServices.Time **系统能力:** SystemCapability.MiscServices.Time
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------- | ---- | ---------------------------- | | -------- | -------------- | ---- | --------------------- |
| callback | AsyncCallback&lt;Date&gt; | 是 | 回调函数,返回当前系统日期。 | | callback | AsyncCallback&lt;Date&gt; | 是 | 回调函数,返回当前系统日期。 |
**示例:** **示例:**
```js ```js
systemTime.getDate((error, data) => { systemTime.getDate((error, data) => {
if (error) { if (error) {
console.error(`failed to systemTime.getDate because ` + JSON.stringify(error)); console.error(`Failed to get system date. Cause:` + JSON.stringify(error));
return; return;
} }
console.log(`systemTime.getDate success data : ` + JSON.stringify(data)); console.log(`Succeeded in getting system date. Data:` + JSON.stringify(data));
}); });
``` ```
## systemTime.getDate<sup>8+</sup> ## systemTime.getDate<sup>8+</sup>
getDate(): Promise&lt;Date&gt; getDate(): Promise&lt;Date&gt;
获取当前系统日期,使用Promise形式返回结果 获取当前系统日期,使用Promise异步回调
**系统能力:** SystemCapability.MiscServices.Time **系统能力:** SystemCapability.MiscServices.Time
...@@ -441,24 +427,23 @@ getDate(): Promise&lt;Date&gt; ...@@ -441,24 +427,23 @@ getDate(): Promise&lt;Date&gt;
| 类型 | 说明 | | 类型 | 说明 |
| ------------------- | ----------------------------------------- | | ------------------- | ----------------------------------------- |
| Promise&lt;Date&gt; | 以Promise形式返回结果,返回当前系统日期。 | | Promise&lt;Date&gt; | Promise对象,返回当前系统日期。 |
**示例:** **示例:**
```js ```js
systemTime.getDate().then((data) => { systemTime.getDate().then((data) => {
console.log(`systemTime.getDate success data : ` + JSON.stringify(data)); console.log(`Succeeded in getting system date. Data:` + JSON.stringify(data));
}).catch((error) => { }).catch((error) => {
console.error(`failed to systemTime.getDate because ` + JSON.stringify(error)); console.error(`Failed to get system date. Cause:` + JSON.stringify(error));
}); });
``` ```
## systemTime.setTimezone ## systemTime.setTimezone
setTimezone(timezone: string, callback: AsyncCallback&lt;void&gt;): void setTimezone(timezone: string, callback: AsyncCallback&lt;void&gt;): void
设置系统时区。 设置系统时区,使用callback异步回调
**需要权限:** ohos.permission.SET_TIME_ZONE **需要权限:** ohos.permission.SET_TIME_ZONE
...@@ -466,29 +451,28 @@ setTimezone(timezone: string, callback: AsyncCallback&lt;void&gt;): void ...@@ -466,29 +451,28 @@ setTimezone(timezone: string, callback: AsyncCallback&lt;void&gt;): void
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------- | ---- | ------------------------------------------ | | -------- | ------------- | ---- | -------------------------- |
| timezone | string | 是 | 系统时区。 | | timezone | string | 是 | 系统时区。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数,可以在回调函数中处理接口返回值。 | | callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。 |
**示例:** **示例:**
```js ```js
systemTime.setTimezone('Asia/Shanghai', (error, data) => { systemTime.setTimezone('Asia/Shanghai', (error, data) => {
if (error) { if (error) {
console.error('failed to systemTime.setTimezone because ' + JSON.stringify(error)); console.error('Failed to set system time zone. Cause:' + JSON.stringify(error));
return; return;
} }
console.info('SystemTimePlugin systemTime.setTimezone success data : ' + JSON.stringify(data)); console.info('Succeeded in setting system time zone. Data:' + JSON.stringify(data));
}); });
``` ```
## systemTime.setTimezone ## systemTime.setTimezone
setTimezone(timezone: string): Promise&lt;void&gt; setTimezone(timezone: string): Promise&lt;void&gt;
设置系统时区。 设置系统时区,使用Promise异步回调
**需要权限:** ohos.permission.SET_TIME_ZONE **需要权限:** ohos.permission.SET_TIME_ZONE
...@@ -504,51 +488,49 @@ setTimezone(timezone: string): Promise&lt;void&gt; ...@@ -504,51 +488,49 @@ setTimezone(timezone: string): Promise&lt;void&gt;
| 类型 | 说明 | | 类型 | 说明 |
| ------------------- | -------------------- | | ------------------- | -------------------- |
| Promise&lt;void&gt; | 返回的异步回调函数。 | | Promise&lt;void&gt; | 无返回结果的Promise对象。 |
**示例:** **示例:**
```js ```js
systemTime.setTimezone('Asia/Shanghai').then((data) => { systemTime.setTimezone('Asia/Shanghai').then((data) => {
console.log(`systemTime.setTimezone success data : ` + JSON.stringify(data)); console.log(`Succeeded in setting system time zone. Data:` + JSON.stringify(data));
}).catch((error) => { }).catch((error) => {
console.error(`failed to systemTime.setTimezone because: ` + JSON.stringify(error)); console.error(`Failed to set system time zone. Cause:` + JSON.stringify(error));
}); });
``` ```
## systemTime.getTimezone<sup>8+</sup> ## systemTime.getTimezone<sup>8+</sup>
getTimezone(callback: AsyncCallback&lt;string&gt;): void getTimezone(callback: AsyncCallback&lt;string&gt;): void
获取系统时区,使用callback形式返回结果 获取系统时区,使用callback异步回调
**系统能力:** SystemCapability.MiscServices.Time **系统能力:** SystemCapability.MiscServices.Time
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------- | ---- | ------------------------ | | -------- | --------- | ---- | ------------------------ |
| callback | AsyncCallback&lt;string&gt; | 是 | 回调函数,返回系统时区。 | | callback | AsyncCallback&lt;string&gt; | 是 | 回调函数,返回系统时区。 |
**示例:** **示例:**
```js ```js
systemTime.getTimezone((error, data) => { systemTime.getTimezone((error, data) => {
if (error) { if (error) {
console.error(`failed to systemTime.getTimezone because ` + JSON.stringify(error)); console.error(`Failed to get system time zone. Cause:` + JSON.stringify(error));
return; return;
} }
console.log(`systemTime.getTimezone success data : ` + JSON.stringify(data)); console.log(`Succeeded in getting system time zone. Data:` + JSON.stringify(data));
}); });
``` ```
## systemTime.getTimezone<sup>8+</sup> ## systemTime.getTimezone<sup>8+</sup>
getTimezone(): Promise&lt;string&gt; getTimezone(): Promise&lt;string&gt;
获取系统时区,使用Promise形式返回结果 获取系统时区,使用Promise异步回调
**系统能力:** SystemCapability.MiscServices.Time **系统能力:** SystemCapability.MiscServices.Time
...@@ -556,14 +538,14 @@ getTimezone(): Promise&lt;string&gt; ...@@ -556,14 +538,14 @@ getTimezone(): Promise&lt;string&gt;
| 类型 | 说明 | | 类型 | 说明 |
| --------------------- | ------------------------------------- | | --------------------- | ------------------------------------- |
| Promise&lt;string&gt; | 以Promise形式返回结果,返回系统时区。 | | Promise&lt;string&gt; | Promise对象,返回系统时区。 |
**示例:** **示例:**
```js ```js
systemTime.getTimezone().then((data) => { systemTime.getTimezone().then((data) => {
console.log(`systemTime.getTimezone success data : ` + JSON.stringify(data)); console.log(`Succeeded in getting system time zone. Data:` + JSON.stringify(data));
}).catch((error) => { }).catch((error) => {
console.error(`failed to systemTime.getTimezone because ` + JSON.stringify(error)); console.error(`Failed to get system time zone. Cause:` + JSON.stringify(error));
}); });
``` ```
\ No newline at end of file \ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册