Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
c67750ed
D
Docs
项目概览
OpenHarmony
/
Docs
1 年多 前同步成功
通知
159
Star
292
Fork
28
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Docs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
c67750ed
编写于
12月 29, 2022
作者:
W
wangtong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
adapt time d.ts
Signed-off-by:
N
wangtong
<
wangtong94@huawei.com
>
上级
a73884fe
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
1121 addition
and
206 deletion
+1121
-206
zh-cn/application-dev/reference/apis/js-apis-system-date-time.md
...pplication-dev/reference/apis/js-apis-system-date-time.md
+665
-0
zh-cn/application-dev/reference/apis/js-apis-system-time.md
zh-cn/application-dev/reference/apis/js-apis-system-time.md
+267
-139
zh-cn/application-dev/reference/apis/js-apis-system-timer.md
zh-cn/application-dev/reference/apis/js-apis-system-timer.md
+118
-67
zh-cn/release-notes/changelogs/OpenHarmony_3.2.10.1/changelog-time.md
...e-notes/changelogs/OpenHarmony_3.2.10.1/changelog-time.md
+71
-0
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-system-date-time.md
0 → 100644
浏览文件 @
c67750ed
# @ohos.systemDateTime (系统时间、时区)
本模块主要由系统时间和系统时区功能组成。开发者可以设置、获取系统时间及系统时区。
> **说明:**
>
> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
## 导入模块
```
js
import
systemDateTime
from
'
@ohos.systemDateTime
'
;
```
## systemDateTime.setTime
setTime(time : number, callback : AsyncCallback
<
void
>
) : void
设置系统时间,使用callback异步回调。
**系统接口:**
此接口为系统接口
**系统能力:**
SystemCapability.MiscServices.Time
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------- | ---- | ---------------- |
| time | number | 是 | 目标时间戳(ms)。 |
| callback | AsyncCallback
<
void
>
| 是 | 回调函数。 |
**示例:**
```
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
<
void
>
设置系统时间,使用Promise异步回调。
**系统接口:**
此接口为系统接口
**系统能力:**
SystemCapability.MiscServices.Time
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------ | ---- | ------------------ |
| time | number | 是 | 目标时间戳(ms)。 |
**返回值:**
| 类型 | 说明 |
| ------------------- | ------------------------- |
| Promise
<
void
>
| 无返回结果的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
<
number
>
): void
获取自Unix纪元以来经过的时间,使用callback异步回调。
**系统能力:**
SystemCapability.MiscServices.Time
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------- | ---- | ------------------ |
| isNano | boolean | 是 | 返回结果是否为纳秒数。
<br>
- true:表示返回结果为纳秒数(ns)。
<br>
- false:表示返回结果为毫秒数(ms)。 |
| callback | AsyncCallback
<
number
>
| 是 | 回调函数,返回自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
<
number
>
): void
获取自Unix纪元以来经过的时间,使用callback异步回调。
**系统能力:**
SystemCapability.MiscServices.Time
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------- | ---- | ---------------------------------- |
| callback | AsyncCallback
<
number
>
| 是 | 回调函数,返回自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
<
number
>
获取自Unix纪元以来经过的时间,使用Promise异步回调。
**系统能力:**
SystemCapability.MiscServices.Time
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------- | ---- | ------------------------- |
| isNano | boolean | 否 | 返回结果是否为纳秒数。
<br/>
- true:表示返回结果为纳秒数(ns)。
<br/>
- false:表示返回结果为毫秒数(ms)。 |
**返回值:**
| 类型 | 说明 |
| --------------------- | --------------------------- |
| Promise
<
number
>
| 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
<
number
>
): void
获取自系统启动以来经过的时间,不包括深度睡眠时间,使用callback异步回调。
**系统能力:**
SystemCapability.MiscServices.Time
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------- | ---- | -------------------------- |
| isNano | boolean | 是 | 返回结果是否为纳秒数。
<br/>
- true:表示返回结果为纳秒数(ns)。
<br/>
- false:表示返回结果为毫秒数(ms)。 |
| callback | AsyncCallback
<
number
>
| 是 | 回调函数,返回自系统启动以来经过的时间,但不包括度睡眠时间。 |
**示例:**
```
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
<
number
>
): void
获取自系统启动以来经过的时间,不包括深度睡眠时间,使用callback异步回调。
**系统能力:**
SystemCapability.MiscServices.Time
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------- | ---- | --------------------- |
| callback | AsyncCallback
<
number
>
| 是 | 回调函数,返回自系统启动以来经过的时间,但不包括度睡眠时间。 |
**示例:**
```
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
<
number
>
获取自系统启动以来经过的时间,不包括深度睡眠时间,使用Promise异步回调。
**系统能力:**
SystemCapability.MiscServices.Time
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------- | ---- | ----------------------------------- |
| isNano | boolean | 否 | 返回结果是否为纳秒数。
<br/>
- true:表示返回结果为纳秒数(ns)。
<br/>
- false:表示返回结果为毫秒数(ms)。 |
**返回值:**
| 类型 | 说明 |
| -------------- | -------------------------------- |
| Promise
<
number
>
| 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
<
number
>
): void
获取自系统启动以来经过的时间,包括深度睡眠时间,使用callback异步回调。
**系统能力:**
SystemCapability.MiscServices.Time
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------- | ---- | ------------------------------- |
| isNano | boolean | 是 | 返回结果是否为纳秒数。
<br/>
- true:表示返回结果为纳秒数(ns)。
<br/>
- false:表示返回结果为毫秒数(ms)。 |
| callback | AsyncCallback
<
number
>
| 是 | 回调函数,返回自系统启动以来经过的时间,包括深度睡眠时间。 |
**示例:**
```
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
<
number
>
): void
获取自系统启动以来经过的时间,包括深度睡眠时间,使用callback异步回调。
**系统能力:**
SystemCapability.MiscServices.Time
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------- | ---- | --------------------------- |
| callback | AsyncCallback
<
number
>
| 是 | 回调函数,返回自系统启动以来经过的时间,包括深度睡眠时间。 |
**示例:**
```
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
<
number
>
获取自系统启动以来经过的时间,包括深度睡眠时间,使用Promise异步回调。
**系统能力:**
SystemCapability.MiscServices.Time
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------- | ---- | ------------------------------- |
| isNano | boolean | 否 | 返回结果是否为纳秒数。
<br/>
- true:表示返回结果为纳秒数(ns)。
<br/>
- false:表示返回结果为毫秒数(ms)。 |
**返回值:**
| 类型 | 说明 |
| --------------------- | ------------------------------- |
| Promise
<
number
>
| 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
<
void
>
): void
设置系统日期,使用callback异步回调。
**系统接口:**
此接口为系统接口
**系统能力:**
SystemCapability.MiscServices.Time
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------- | ---- | --------------------- |
| date | Date | 是 | 目标日期。 |
| callback | AsyncCallback
<
void
>
| 是 | 回调函数。 |
**示例:**
```
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
<
void
>
设置系统日期,使用Promise异步回调。
**系统接口:**
此接口为系统接口
**系统能力:**
SystemCapability.MiscServices.Time
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ---- | ---- | ---------- |
| date | Date | 是 | 目标日期。 |
**返回值:**
| 类型 | 说明 |
| ------------------- | -------------------- |
| Promise
<
void
>
| 无返回结果的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
<
Date
>
): void
获取当前系统日期,使用callback异步回调。
**系统能力:**
SystemCapability.MiscServices.Time
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------- | ---- | --------------------- |
| callback | AsyncCallback
<
Date
>
| 是 | 回调函数,返回当前系统日期。 |
**示例:**
```
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
<
Date
>
获取当前系统日期,使用Promise异步回调。
**系统能力:**
SystemCapability.MiscServices.Time
**返回值:**
| 类型 | 说明 |
| ------------------- | ----------------------------------------- |
| Promise
<
Date
>
| 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
<
void
>
): void
设置系统时区,使用callback异步回调。
**系统接口:**
此接口为系统接口
**系统能力:**
SystemCapability.MiscServices.Time
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------- | ---- | -------------------------- |
| timezone | string | 是 | 系统时区。 具体可见
[
支持的系统时区
](
#支持的系统时区
)
。 |
| callback | AsyncCallback
<
void
>
| 是 | 回调函数。 |
**示例:**
```
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
<
void
>
设置系统时区,使用Promise异步回调。
**系统接口:**
此接口为系统接口
**系统能力:**
SystemCapability.MiscServices.Time
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------ | ---- | ---------- |
| timezone | string | 是 | 系统时区。具体可见
[
支持的系统时区
](
#支持的系统时区
)
。 |
**返回值:**
| 类型 | 说明 |
| ------------------- | -------------------- |
| Promise
<
void
>
| 无返回结果的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
<
string
>
): void
获取系统时区,使用callback异步回调。
**系统能力:**
SystemCapability.MiscServices.Time
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------- | ---- | ------------------------ |
| callback | AsyncCallback
<
string
>
| 是 | 回调函数,返回系统时区。具体可见
[
支持的系统时区
](
#支持的系统时区
)
。 |
**示例:**
```
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
<
string
>
获取系统时区,使用Promise异步回调。
**系统能力:**
SystemCapability.MiscServices.Time
**返回值:**
| 类型 | 说明 |
| --------------------- | ------------------------------------- |
| Promise
<
string
>
| 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
zh-cn/application-dev/reference/apis/js-apis-system-time.md
浏览文件 @
c67750ed
...
...
@@ -12,7 +12,7 @@
import
systemTime
from
'
@ohos.systemTime
'
;
```
## systemTime.setTime
## systemTime.setTime
<sup>(deprecated)</sup>
setTime(time : number, callback : AsyncCallback
<
void
>
) : void
...
...
@@ -34,16 +34,20 @@ setTime(time : number, callback : AsyncCallback<void>) : void
```
js
// time对应的时间为2021-01-20 02:36:25
let
time
=
1611081385000
;
systemTime
.
setTime
(
time
,
(
error
,
data
)
=>
{
if
(
error
)
{
console
.
error
(
`Failed to set systemTime. Cause:`
+
JSON
.
stringify
(
error
));
return
;
}
console
.
log
(
`Succeeded in setting systemTime. Data:`
+
JSON
.
stringify
(
data
));
});
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`
);
});
}
catch
(
e
)
{
console
.
info
(
`Failed to set time. message:
${
e
.
message
}
, code:
${
e
.
code
}
`
);
}
```
## systemTime.setTime
## systemTime.setTime
<sup>(deprecated)</sup>
setTime(time : number) : Promise
<
void
>
...
...
@@ -70,19 +74,27 @@ setTime(time : number) : Promise<void>
```
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>
## systemTime.getCurrentTime<sup>
(deprecated)
</sup>
getCurrentTime(isNano: boolean, callback: AsyncCallback
<
number
>
): void
获取自Unix纪元以来经过的时间,使用callback异步回调。
> **说明:**
>
> 从 API Version 7 开始支持,从 API Version 9 开始废弃,建议使用[systemDateTime.getCurrentTime](./js-apis-system-date-time.md#systemdatetimegetcurrenttime)替代。
**系统能力:**
SystemCapability.MiscServices.Time
**参数:**
...
...
@@ -95,21 +107,29 @@ getCurrentTime(isNano: boolean, callback: AsyncCallback<number>): void
**示例:**
```
js
systemTime
.
getCurrentTime
(
true
,
(
error
,
data
)
=>
{
if
(
error
)
{
console
.
error
(
`Failed to get systemTime. Cause:`
+
JSON
.
stringify
(
error
));
return
;
}
console
.
log
(
`Succeeded in getting systemTime. Data:`
+
JSON
.
stringify
(
data
));
});
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
}
`
);
});
}
catch
(
e
)
{
console
.
info
(
`Failed to get currentTime. message:
${
e
.
message
}
, code:
${
e
.
code
}
`
);
}
```
## systemTime.getCurrentTime<sup>
8+
</sup>
## systemTime.getCurrentTime<sup>
(deprecated)
</sup>
getCurrentTime(callback: AsyncCallback
<
number
>
): void
获取自Unix纪元以来经过的时间,使用callback异步回调。
> **说明:**
>
> 从 API Version 7 开始支持,从 API Version 9 开始废弃,建议使用[systemDateTime.getCurrentTime](./js-apis-system-date-time.md#systemdatetimegetcurrenttime-1)替代。
**系统能力:**
SystemCapability.MiscServices.Time
**参数:**
...
...
@@ -121,21 +141,29 @@ getCurrentTime(callback: AsyncCallback<number>): void
**示例:**
```
js
systemTime
.
getCurrentTime
((
error
,
data
)
=>
{
if
(
error
)
{
console
.
error
(
`Succeeded in getting systemTime. Data:`
+
JSON
.
stringify
(
error
));
return
;
}
console
.
log
(
`Failed to get systemTime. Cause:`
+
JSON
.
stringify
(
data
));
});
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
}
`
);
});
}
catch
(
e
)
{
console
.
info
(
`Failed to get currentTime. message:
${
e
.
message
}
, code:
${
e
.
code
}
`
);
}
```
## systemTime.getCurrentTime<sup>
8+
</sup>
## systemTime.getCurrentTime<sup>
(deprecated)
</sup>
getCurrentTime(isNano?: boolean): Promise
<
number
>
获取自Unix纪元以来经过的时间,使用Promise异步回调。
> **说明:**
>
> 从 API Version 7 开始支持,从 API Version 9 开始废弃,建议使用[systemDateTime.getCurrentTime](./js-apis-system-date-time.md#systemdatetimegetcurrenttime-2)替代。
**系统能力:**
SystemCapability.MiscServices.Time
**参数:**
...
...
@@ -153,19 +181,27 @@ getCurrentTime(isNano?: boolean): Promise<number>
**示例:**
```
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>
## systemTime.getRealActiveTime<sup>
(deprecated)
</sup>
getRealActiveTime(isNano: boolean, callback: AsyncCallback
<
number
>
): void
获取自系统启动以来经过的时间,不包括深度睡眠时间,使用callback异步回调。
> **说明:**
>
> 从 API Version 7 开始支持,从 API Version 9 开始废弃,建议使用[systemDateTime.getRealActiveTime](./js-apis-system-date-time.md#systemdatetimegetrealactivetime)替代。
**系统能力:**
SystemCapability.MiscServices.Time
**参数:**
...
...
@@ -178,21 +214,29 @@ getRealActiveTime(isNano: boolean, callback: AsyncCallback<number>): void
**示例:**
```
js
systemTime
.
getRealActiveTime
(
true
,
(
error
,
data
)
=>
{
if
(
error
)
{
console
.
error
(
`Failed to get real active time. Cause:`
+
JSON
.
stringify
(
error
));
return
;
}
console
.
log
(
`Succeeded in getting real active time. Data:`
+
JSON
.
stringify
(
data
));
});
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
}
`
);
});
}
catch
(
e
)
{
console
.
info
(
`Failed to get real active time. message:
${
e
.
message
}
, code:
${
e
.
code
}
`
);
}
```
## systemTime.getRealActiveTime<sup>
8+
</sup>
## systemTime.getRealActiveTime<sup>
(deprecated)
</sup>
getRealActiveTime(callback: AsyncCallback
<
number
>
): void
获取自系统启动以来经过的时间,不包括深度睡眠时间,使用callback异步回调。
> **说明:**
>
> 从 API Version 7 开始支持,从 API Version 9 开始废弃,建议使用[systemDateTime.getRealActiveTime](./js-apis-system-date-time.md#systemdatetimegetrealactivetime-1)替代。
**系统能力:**
SystemCapability.MiscServices.Time
**参数:**
...
...
@@ -204,21 +248,29 @@ getRealActiveTime(callback: AsyncCallback<number>): void
**示例:**
```
js
systemTime
.
getRealActiveTime
((
error
,
data
)
=>
{
if
(
error
)
{
console
.
error
(
`Failed to get real active time. Cause:`
+
JSON
.
stringify
(
error
));
return
;
}
console
.
log
(
`Succeeded in getting real active time. Data:`
+
JSON
.
stringify
(
data
));
});
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
}
`
);
});
}
catch
(
e
)
{
console
.
info
(
`Failed to get real active time. message:
${
e
.
message
}
, code:
${
e
.
code
}
`
);
}
```
## systemTime.getRealActiveTime<sup>
8+
</sup>
## systemTime.getRealActiveTime<sup>
(deprecated)
</sup>
getRealActiveTime(isNano?: boolean): Promise
<
number
>
获取自系统启动以来经过的时间,不包括深度睡眠时间,使用Promise异步回调。
> **说明:**
>
> 从 API Version 7 开始支持,从 API Version 9 开始废弃,建议使用[systemDateTime.getRealActiveTime](./js-apis-system-date-time.md#systemdatetimegetrealactivetime-2)替代。
**系统能力:**
SystemCapability.MiscServices.Time
**参数:**
...
...
@@ -236,19 +288,27 @@ getRealActiveTime(isNano?: boolean): Promise<number>
**示例:**
```
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>
## systemTime.getRealTime<sup>
(deprecated)
</sup>
getRealTime(isNano: boolean, callback: AsyncCallback
<
number
>
): void
获取自系统启动以来经过的时间,包括深度睡眠时间,使用callback异步回调。
> **说明:**
>
> 从 API Version 7 开始支持,从 API Version 9 开始废弃,建议使用[systemDateTime.getRealTime](./js-apis-system-date-time.md#systemdatetimegetrealtime)替代。
**系统能力:**
SystemCapability.MiscServices.Time
**参数:**
...
...
@@ -261,21 +321,29 @@ getRealTime(isNano: boolean, callback: AsyncCallback<number>): void
**示例:**
```
js
systemTime
.
getRealTime
(
true
,
(
error
,
data
)
=>
{
if
(
error
)
{
console
.
error
(
`Failed to get real time. Cause:`
+
JSON
.
stringify
(
error
));
return
;
}
console
.
log
(
`Succeeded in getting real time. Data:`
+
JSON
.
stringify
(
data
));
});
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
}
`
);
});
}
catch
(
e
)
{
console
.
info
(
`Failed to get real time. message:
${
e
.
message
}
, code:
${
e
.
code
}
`
);
}
```
## systemTime.getRealTime<sup>
8+
</sup>
## systemTime.getRealTime<sup>
(deprecated)
</sup>
getRealTime(callback: AsyncCallback
<
number
>
): void
获取自系统启动以来经过的时间,包括深度睡眠时间,使用callback异步回调。
> **说明:**
>
> 从 API Version 7 开始支持,从 API Version 9 开始废弃,建议使用[systemDateTime.getRealTime](./js-apis-system-date-time.md#systemdatetimegetrealtime-1)替代。
**系统能力:**
SystemCapability.MiscServices.Time
**参数:**
...
...
@@ -287,28 +355,36 @@ getRealTime(callback: AsyncCallback<number>): void
**示例:**
```
js
systemTime
.
getRealTime
((
error
,
data
)
=>
{
if
(
error
)
{
console
.
error
(
`Failed to get real time. Cause:`
+
JSON
.
stringify
(
error
));
return
;
}
console
.
log
(
`Succeeded in getting real time. Data:`
+
JSON
.
stringify
(
data
));
});
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
}
`
);
});
}
catch
(
e
)
{
console
.
info
(
`Failed to get real time. message:
${
e
.
message
}
, code:
${
e
.
code
}
`
);
}
```
## systemTime.getRealTime<sup>
8+
</sup>
## systemTime.getRealTime<sup>
(deprecated)
</sup>
getRealTime(isNano?: boolean): Promise
<
number
>
获取自系统启动以来经过的时间,包括深度睡眠时间,使用Promise异步回调。
> **说明:**
>
> 从 API Version 7 开始支持,从 API Version 9 开始废弃,建议使用[systemDateTime.getRealTime](./js-apis-system-date-time.md#systemdatetimegetrealtime-2)替代。
**系统能力:**
SystemCapability.MiscServices.Time
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------- | ---- | ------------------------------- |
| isNano | boolean | 否 | 返回结果是否为纳秒数。
<
<
br
/>
- true:表示返回结果为纳秒数(ns)。
<br/>
- false:表示返回结果为毫秒数(ms)。 |
| isNano | boolean | 否 | 返回结果是否为纳秒数。
<br/>
- true:表示返回结果为纳秒数(ns)。
<br/>
- false:表示返回结果为毫秒数(ms)。 |
**返回值:**
...
...
@@ -319,14 +395,18 @@ getRealTime(isNano?: boolean): Promise<number>
**示例:**
```
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
## systemTime.setDate
<sup>(deprecated)</sup>
setDate(date: Date, callback: AsyncCallback
<
void
>
): void
...
...
@@ -346,17 +426,21 @@ setDate(date: Date, callback: AsyncCallback<void>): void
**示例:**
```
js
let
data
=
new
Date
();
systemTime
.
setDate
(
data
,(
error
,
data
)
=>
{
if
(
error
)
{
console
.
error
(
'
Failed to set system date. Cause:
'
+
JSON
.
stringify
(
error
));
return
;
}
console
.
info
(
'
Succeeded in setting system date. Data:
'
+
JSON
.
stringify
(
data
));
});
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.`
);
});
}
catch
(
e
)
{
console
.
info
(
`Failed to set date. message:
${
e
.
message
}
, code:
${
e
.
code
}
`
);
}
```
## systemTime.setDate
## systemTime.setDate
<sup>(deprecated)</sup>
setDate(date: Date): Promise
<
void
>
...
...
@@ -381,20 +465,28 @@ setDate(date: Date): Promise<void>
**示例:**
```
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>
## systemTime.getDate<sup>
(deprecated)
</sup>
getDate(callback: AsyncCallback
<
Date
>
): void
获取当前系统日期,使用callback异步回调。
> **说明:**
>
> 从 API Version 7 开始支持,从 API Version 9 开始废弃,建议使用[systemDateTime.getDate](./js-apis-system-date-time.md#systemdatetimegetdate)替代。
**系统能力:**
SystemCapability.MiscServices.Time
**参数:**
...
...
@@ -406,21 +498,29 @@ getDate(callback: AsyncCallback<Date>): void
**示例:**
```
js
systemTime
.
getDate
((
error
,
data
)
=>
{
if
(
error
)
{
console
.
error
(
`Failed to get system date. Cause:`
+
JSON
.
stringify
(
error
));
return
;
}
console
.
log
(
`Succeeded in getting system date. Data:`
+
JSON
.
stringify
(
data
));
});
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
}
`
);;
});
}
catch
(
e
)
{
console
.
info
(
`Failed to get date. message:
${
e
.
message
}
, code:
${
e
.
code
}
`
);
}
```
## systemTime.getDate<sup>
8+
</sup>
## systemTime.getDate<sup>
(deprecated)
</sup>
getDate(): Promise
<
Date
>
获取当前系统日期,使用Promise异步回调。
> **说明:**
>
> 从 API Version 7 开始支持,从 API Version 9 开始废弃,建议使用[systemDateTime.getDate](./js-apis-system-date-time.md#systemdatetimegetdate-1)替代。
**系统能力:**
SystemCapability.MiscServices.Time
**返回值:**
...
...
@@ -432,14 +532,18 @@ getDate(): Promise<Date>
**示例:**
```
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
## systemTime.setTimezone
<sup>(deprecated)</sup>
setTimezone(timezone: string, callback: AsyncCallback
<
void
>
): void
...
...
@@ -459,16 +563,20 @@ setTimezone(timezone: string, callback: AsyncCallback<void>): void
**示例:**
```
js
systemTime
.
setTimezone
(
'
Asia/Shanghai
'
,
(
error
,
data
)
=>
{
if
(
error
)
{
console
.
error
(
'
Failed to set system time zone. Cause:
'
+
JSON
.
stringify
(
error
));
return
;
}
console
.
info
(
'
Succeeded in setting system time zone. Data:
'
+
JSON
.
stringify
(
data
));
});
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.`
);
});
}
catch
(
e
)
{
console
.
info
(
`Failed to set timezone. message:
${
e
.
message
}
, code:
${
e
.
code
}
`
);
}
```
## systemTime.setTimezone
## systemTime.setTimezone
<sup>(deprecated)</sup>
setTimezone(timezone: string): Promise
<
void
>
...
...
@@ -493,19 +601,27 @@ setTimezone(timezone: string): Promise<void>
**示例:**
```
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>
## systemTime.getTimezone<sup>
(deprecated)
</sup>
getTimezone(callback: AsyncCallback
<
string
>
): void
获取系统时区,使用callback异步回调。
> **说明:**
>
> 从 API Version 7 开始支持,从 API Version 9 开始废弃,建议使用[systemDateTime.getTimezone](./js-apis-system-date-time.md#systemdatetimegettimezone)替代。
**系统能力:**
SystemCapability.MiscServices.Time
**参数:**
...
...
@@ -517,21 +633,29 @@ getTimezone(callback: AsyncCallback<string>): void
**示例:**
```
js
systemTime
.
getTimezone
((
error
,
data
)
=>
{
if
(
error
)
{
console
.
error
(
`Failed to get system time zone. Cause:`
+
JSON
.
stringify
(
error
));
return
;
}
console
.
log
(
`Succeeded in getting system time zone. Data:`
+
JSON
.
stringify
(
data
));
});
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
}
`
);;
});
}
catch
(
e
)
{
console
.
info
(
`Failed to get timezone. message:
${
e
.
message
}
, code:
${
e
.
code
}
`
);
}
```
## systemTime.getTimezone<sup>
8+
</sup>
## systemTime.getTimezone<sup>
(deprecated)
</sup>
getTimezone(): Promise
<
string
>
获取系统时区,使用Promise异步回调。
> **说明:**
>
> 从 API Version 7 开始支持,从 API Version 9 开始废弃,建议使用[systemDateTime.getTimezone](#syste./js-apis-system-date-time.md#systemdatetimegettimezone-1)替代。
**系统能力:**
SystemCapability.MiscServices.Time
**返回值:**
...
...
@@ -543,11 +667,15 @@ getTimezone(): Promise<string>
**示例:**
```
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
}
`
);
}
```
## 支持的系统时区
...
...
zh-cn/application-dev/reference/apis/js-apis-system-timer.md
浏览文件 @
c67750ed
...
...
@@ -35,7 +35,7 @@ import systemTimer from '@ohos.systemTimer';
| 名称 | 类型 | 必填 | 说明 |
| --------- | --------------------------------------------- | ---- | ------------------------------------------------------------ |
| 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-app-ability-wantAgent.md
)
| 否 | 设置通知的WantAgent,定时器到期后通知。(支持拉起应用MainAbility,暂不支持拉起ServiceAbility。) |
...
...
@@ -48,6 +48,8 @@ createTimer(options: TimerOptions, callback: AsyncCallback<number>): void
创建定时器,使用callback异步回调。
**系统接口:**
此接口为系统接口
**系统能力:**
SystemCapability.MiscServices.Time
**参数:**
...
...
@@ -66,13 +68,17 @@ export default {
type
:
systemTimer
.
TIMER_TYPE_REALTIME
,
repeat
:
false
};
systemTimer
.
createTimer
(
options
,
(
error
,
data
)
=>
{
if
(
error
)
{
console
.
error
(
`Failed to create timer. Cause:`
+
JSON
.
stringify
(
error
));
return
;
}
console
.
log
(
`Succeeded in creating timer. Data:`
+
JSON
.
stringify
(
data
));
});
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
}
`
);
}
}
}
```
...
...
@@ -83,6 +89,8 @@ createTimer(options: TimerOptions): Promise<number>
创建定时器,使用Promise异步回调。
**系统接口:**
此接口为系统接口
**系统能力:**
SystemCapability.MiscServices.Time
**参数:**
...
...
@@ -105,12 +113,16 @@ export default {
let
options
=
{
type
:
systemTimer
.
TIMER_TYPE_REALTIME
,
repeat
:
false
};
systemTimer
.
createTimer
(
options
).
then
((
data
)
=>
{
console
.
log
(
`Succeeded in creating timer. Data:`
+
JSON
.
stringify
(
data
));
}).
catch
((
error
)
=>
{
console
.
error
(
`Failed to create timer. Cause:`
+
JSON
.
stringify
(
error
));
});
};
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
}
`
);
}
}
}
```
...
...
@@ -121,6 +133,8 @@ startTimer(timer: number, triggerTime: number, callback: AsyncCallback<void&g
开始定时器,使用callback异步回调。
**系统接口:**
此接口为系统接口
**系统能力:**
SystemCapability.MiscServices.Time
**参数:**
...
...
@@ -143,12 +157,17 @@ export default {
let
timerId
=
await
systemTimer
.
createTimer
(
options
)
let
triggerTime
=
new
Date
().
getTime
()
triggerTime
+=
3000
systemTimer
.
startTimer
(
timerId
,
triggerTime
,
(
error
)
=>
{
if
(
error
)
{
console
.
error
(
`Failed to start timer. Cause:`
+
JSON
.
stringify
(
error
));
return
;
}
});
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
}
`
);
}
}
}
```
...
...
@@ -159,6 +178,8 @@ startTimer(timer: number, triggerTime: number): Promise<void>
开始定时器,使用Promise异步回调。
**系统接口:**
此接口为系统接口
**系统能力:**
SystemCapability.MiscServices.Time
**参数:**
...
...
@@ -186,11 +207,15 @@ export default {
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
));
}).
catch
((
error
)
=>
{
console
.
error
(
`Failed to start timer. Cause:`
+
JSON
.
stringify
(
error
));
});
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
}
`
);
}
}
}
```
...
...
@@ -201,6 +226,8 @@ stopTimer(timer: number, callback: AsyncCallback<void>): void
停止定时器,使用callback异步回调。
**系统接口:**
此接口为系统接口
**系统能力:**
SystemCapability.MiscServices.Time
**参数:**
...
...
@@ -214,22 +241,27 @@ stopTimer(timer: number, callback: AsyncCallback<void>): void
```
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
,
(
error
)
=>
{
if
(
error
)
{
console
.
error
(
`Failed to stop timer. Cause:`
+
JSON
.
stringify
(
error
));
return
;
}
});
}
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
}
`
);
}
}
}
```
...
...
@@ -239,6 +271,8 @@ stopTimer(timer: number): Promise<void>
停止定时器,使用Promise异步回调。
**系统接口:**
此接口为系统接口
**系统能力:**
SystemCapability.MiscServices.Time
**参数:**
...
...
@@ -257,21 +291,25 @@ stopTimer(timer: number): Promise<void>
```
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
).
then
((
data
)
=>
{
console
.
log
(
`Succeeded in stopping timer. Data:`
+
JSON
.
stringify
(
data
));
}).
catch
((
error
)
=>
{
console
.
error
(
`Failed to stop timer. Cause:`
+
JSON
.
stringify
(
error
));
});
}
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
}
`
);
}
}
}
```
...
...
@@ -281,6 +319,8 @@ destroyTimer(timer: number, callback: AsyncCallback<void>): void
销毁定时器,使用callback异步回调。
**系统接口:**
此接口为系统接口
**系统能力:**
SystemCapability.MiscServices.Time
**参数:**
...
...
@@ -304,12 +344,17 @@ export default {
triggerTime
+=
3000
systemTimer
.
startTimer
(
timerId
,
triggerTime
)
systemTimer
.
stopTimer
(
timerId
)
systemTimer
.
destroyTimer
(
timerId
,
(
error
)
=>
{
if
(
error
)
{
console
.
error
(
`Failed to destroy timer. Cause:`
+
JSON
.
stringify
(
error
));
return
;
}
});
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
}
`
);
}
}
}
```
...
...
@@ -320,6 +365,8 @@ destroyTimer(timer: number): Promise<void>
销毁定时器,使用Promise异步回调。
**系统接口:**
此接口为系统接口
**系统能力:**
SystemCapability.MiscServices.Time
**参数:**
...
...
@@ -348,11 +395,15 @@ export default {
triggerTime
+=
3000
systemTimer
.
startTimer
(
timerId
,
triggerTime
)
systemTimer
.
stopTimer
(
timerId
)
systemTimer
.
destroyTimer
(
timerId
).
then
((
data
)
=>
{
console
.
log
(
`Succeeded in destroying timer. Data:`
+
JSON
.
stringify
(
data
));
}).
catch
((
error
)
=>
{
console
.
error
(
`Failed to destroy timer. Cause:`
+
JSON
.
stringify
(
error
));
});
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
}
`
);
}
}
}
```
\ No newline at end of file
zh-cn/release-notes/changelogs/OpenHarmony_3.2.10.1/changelog-time.md
0 → 100644
浏览文件 @
c67750ed
# 时间时区子系统ChangeLog
## cl.time.1 接口异常抛出变更
时间时区子系统时间相关接口异常抛出:201权限否定异常、202非系统应用异常和401参数无效异常。
**变更影响**
基于此前版本开发的应用,继续使用无影响,使用新接口需要捕获并处理抛出的新异常。
**关键接口/组件变更**
变更前:
-
接口异常抛出message,错误码-1。
变更后:
-
接口异常抛出message和code,包括201权限否定异常、202非系统应用异常和401参数无效异常。
原接口中标记为废弃的接口,可以使用新接口中的同名接口替换
| 原接口 | 新接口 |
| ---------------- | -------------------- |
| @ohos.systemTime | @ohos.systemDateTime |
**适配指导**
应用中调用systemTime所有接口可参考下列代码进行异常捕获,以setTime接口为例,其他接口适配方法相同。
callback形式调用:
**示例:**
```
js
import
systemDateTime
from
@
ohos
.
systemDateTime
// time对应的时间为2021-01-20 02:36:25
let
time
=
1611081385000
;
try
{
systemDateTime
.
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
}
`
);
}
```
promise形式调用:
**示例:**
```
js
import
systemDateTime
from
@
ohos
.
systemDateTime
// 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 setting time. message:
${
error
.
message
}
, code:
${
error
.
code
}
`
);
});
}
catch
(
e
)
{
//捕获参数校验失败异常
console
.
info
(
`Failed to set time. message:
${
e
.
message
}
, code:
${
e
.
code
}
`
);
}
```
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录