Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
8ff6ec1b
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看板
未验证
提交
8ff6ec1b
编写于
1月 16, 2023
作者:
O
openharmony_ci
提交者:
Gitee
1月 16, 2023
浏览文件
操作
浏览文件
下载
差异文件
!13555 资料需求回合
Merge pull request !13555 from wTong888/cherry-pick-1673572732
上级
75468e2c
424e39c5
变更
4
展开全部
隐藏空白更改
内联
并排
Showing
4 changed file
with
1252 addition
and
300 deletion
+1252
-300
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
+415
-187
zh-cn/application-dev/reference/apis/js-apis-system-timer.md
zh-cn/application-dev/reference/apis/js-apis-system-timer.md
+148
-113
zh-cn/application-dev/reference/errorcodes/errorcode-time.md
zh-cn/application-dev/reference/errorcodes/errorcode-time.md
+24
-0
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-system-date-time.md
0 → 100644
浏览文件 @
8ff6ec1b
此差异已折叠。
点击以展开。
zh-cn/application-dev/reference/apis/js-apis-system-time.md
浏览文件 @
8ff6ec1b
此差异已折叠。
点击以展开。
zh-cn/application-dev/reference/apis/js-apis-system-timer.md
浏览文件 @
8ff6ec1b
...
@@ -20,12 +20,12 @@ import systemTimer from '@ohos.systemTimer';
...
@@ -20,12 +20,12 @@ import systemTimer from '@ohos.systemTimer';
**系统能力:**
SystemCapability.MiscServices.Time
**系统能力:**
SystemCapability.MiscServices.Time
| 名称 | 类型 | 值 | 说明 |
| 名称 | 类型 | 值 | 说明
|
| ------------------- | ------ | ---- | ---------------------------- |
| ------------------- | ------ | ---- | ----------------------------
--------------------------------
|
| TIMER_TYPE_REALTIME | number | 1 | 系统启动时间定时器。(定时器启动时间不能晚于当前设置的系统时间)
|
| TIMER_TYPE_REALTIME | number | 1 | 系统启动时间定时器。(定时器启动时间不能晚于当前设置的系统时间) |
| TIMER_TYPE_WAKEUP | number | 2 | 唤醒定时器。 |
| TIMER_TYPE_WAKEUP | number | 2 | 唤醒定时器。
|
| TIMER_TYPE_EXACT | number | 4 | 精准定时器。 |
| TIMER_TYPE_EXACT | number | 4 | 精准定时器。
|
| TIMER_TYPE_IDLE | number | 8 | IDLE模式定时器(暂不支持)。 |
| TIMER_TYPE_IDLE | number | 8 | IDLE模式定时器(暂不支持)。
|
## TimerOptions
## TimerOptions
...
@@ -33,13 +33,13 @@ import systemTimer from '@ohos.systemTimer';
...
@@ -33,13 +33,13 @@ import systemTimer from '@ohos.systemTimer';
**系统能力:**
SystemCapability.MiscServices.Time
**系统能力:**
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为单次定时器。 |
| repeat | boolean
| 是 | true为循环定时器,false为单次定时器。 |
| interval | number | 否 | 如果是循环定时器,repeat值应大于5000毫秒,非重复定时器置为0。 |
| 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。 |
| callback | number
| 是 | 以回调函数的形式返回定时器的ID。 |
## systemTimer.createTimer
## systemTimer.createTimer
...
@@ -61,19 +61,23 @@ createTimer(options: TimerOptions, callback: AsyncCallback<number>): void
...
@@ -61,19 +61,23 @@ createTimer(options: TimerOptions, callback: AsyncCallback<number>): void
```
js
```
js
export
default
{
export
default
{
systemTimer
()
{
systemTimer
()
{
let
options
=
{
let
options
=
{
type
:
systemTimer
.
TIMER_TYPE_REALTIME
,
type
:
systemTimer
.
TIMER_TYPE_REALTIME
,
repeat
:
false
repeat
:
false
};
};
systemTimer
.
createTimer
(
options
,
(
error
,
data
)
=>
{
try
{
if
(
error
)
{
systemTimer
.
createTimer
(
options
,
(
error
,
timerId
)
=>
{
console
.
error
(
`Failed to create timer. Cause:`
+
JSON
.
stringify
(
error
));
if
(
error
)
{
return
;
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
}
`
);
}
}
}
}
}
```
```
...
@@ -101,17 +105,21 @@ createTimer(options: TimerOptions): Promise<number>
...
@@ -101,17 +105,21 @@ createTimer(options: TimerOptions): Promise<number>
```
js
```
js
export
default
{
export
default
{
systemTimer
()
{
systemTimer
()
{
let
options
=
{
let
options
=
{
type
:
systemTimer
.
TIMER_TYPE_REALTIME
,
type
:
systemTimer
.
TIMER_TYPE_REALTIME
,
repeat
:
false
repeat
:
false
};
};
systemTimer
.
createTimer
(
options
).
then
((
data
)
=>
{
try
{
console
.
log
(
`Succeeded in creating timer. Data:`
+
JSON
.
stringify
(
data
));
systemTimer
.
createTimer
(
options
).
then
((
timerId
)
=>
{
}).
catch
((
error
)
=>
{
console
.
info
(
`Succeeded in creating timer. timerId:
${
timerId
}
`
);
console
.
error
(
`Failed to create timer. Cause:`
+
JSON
.
stringify
(
error
));
}).
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
}
`
);
}
}
}
}
}
```
```
...
@@ -135,21 +143,26 @@ startTimer(timer: number, triggerTime: number, callback: AsyncCallback<void&g
...
@@ -135,21 +143,26 @@ startTimer(timer: number, triggerTime: number, callback: AsyncCallback<void&g
```
js
```
js
export
default
{
export
default
{
async
systemTimer
()
{
async
systemTimer
()
{
let
options
=
{
let
options
=
{
type
:
systemTimer
.
TIMER_TYPE_REALTIME
,
type
:
systemTimer
.
TIMER_TYPE_REALTIME
,
repeat
:
false
repeat
:
false
}
}
let
timerId
=
await
systemTimer
.
createTimer
(
options
)
let
timerId
=
await
systemTimer
.
createTimer
(
options
);
let
triggerTime
=
new
Date
().
getTime
()
let
triggerTime
=
new
Date
().
getTime
();
triggerTime
+=
3000
triggerTime
+=
3000
;
try
{
systemTimer
.
startTimer
(
timerId
,
triggerTime
,
(
error
)
=>
{
systemTimer
.
startTimer
(
timerId
,
triggerTime
,
(
error
)
=>
{
if
(
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
;
return
;
}
}
console
.
info
(
`Succeeded in starting timer.`
);
});
});
}
catch
(
e
)
{
console
.
info
(
`Failed to start timer. message:
${
e
.
message
}
, code:
${
e
.
code
}
`
);
}
}
}
}
}
```
```
...
@@ -178,20 +191,24 @@ startTimer(timer: number, triggerTime: number): Promise<void>
...
@@ -178,20 +191,24 @@ startTimer(timer: number, triggerTime: number): Promise<void>
```
js
```
js
export
default
{
export
default
{
async
systemTimer
(){
async
systemTimer
(){
let
options
=
{
let
options
=
{
type
:
systemTimer
.
TIMER_TYPE_REALTIME
,
type
:
systemTimer
.
TIMER_TYPE_REALTIME
,
repeat
:
false
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
));
}).
catch
((
error
)
=>
{
console
.
error
(
`Failed to start timer. Cause:`
+
JSON
.
stringify
(
error
));
});
}
}
let
timerId
=
await
systemTimer
.
createTimer
(
options
);
let
triggerTime
=
new
Date
().
getTime
();
triggerTime
+=
3000
;
try
{
systemTimer
.
startTimer
(
timerId
,
triggerTime
).
then
(()
=>
{
console
.
info
(
`Succeeded in starting timer.`
);
}).
catch
((
error
)
=>
{
console
.
info
(
`Failed to start timer. message:
${
error
.
message
}
, code:
${
error
.
code
}
`
);
});
}
catch
(
e
)
{
console
.
info
(
`Failed to start timer. message:
${
e
.
message
}
, code:
${
e
.
code
}
`
);
}
}
}
}
```
```
...
@@ -215,20 +232,25 @@ stopTimer(timer: number, callback: AsyncCallback<void>): void
...
@@ -215,20 +232,25 @@ stopTimer(timer: number, callback: AsyncCallback<void>): void
```
js
```
js
export
default
{
export
default
{
async
systemTimer
()
{
async
systemTimer
()
{
let
options
=
{
let
options
=
{
type
:
systemTimer
.
TIMER_TYPE_REALTIME
,
type
:
systemTimer
.
TIMER_TYPE_REALTIME
,
repeat
:
false
repeat
:
false
}
}
let
timerId
=
await
systemTimer
.
createTimer
(
options
)
let
timerId
=
await
systemTimer
.
createTimer
(
options
);
let
triggerTime
=
new
Date
().
getTime
()
let
triggerTime
=
new
Date
().
getTime
();
triggerTime
+=
3000
triggerTime
+=
3000
;
systemTimer
.
startTimer
(
timerId
,
triggerTime
)
systemTimer
.
startTimer
(
timerId
,
triggerTime
);
try
{
systemTimer
.
stopTimer
(
timerId
,
(
error
)
=>
{
systemTimer
.
stopTimer
(
timerId
,
(
error
)
=>
{
if
(
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
;
return
;
}
}
console
.
info
(
`Succeeded in stopping timer.`
);
});
});
}
catch
(
e
)
{
console
.
info
(
`Failed to stop timer. message:
${
e
.
message
}
, code:
${
e
.
code
}
`
);
}
}
}
}
}
```
```
...
@@ -258,19 +280,23 @@ stopTimer(timer: number): Promise<void>
...
@@ -258,19 +280,23 @@ stopTimer(timer: number): Promise<void>
```
js
```
js
export
default
{
export
default
{
async
systemTimer
(){
async
systemTimer
(){
let
options
=
{
let
options
=
{
type
:
systemTimer
.
TIMER_TYPE_REALTIME
,
type
:
systemTimer
.
TIMER_TYPE_REALTIME
,
repeat
:
false
repeat
:
false
}
}
let
timerId
=
await
systemTimer
.
createTimer
(
options
)
let
timerId
=
await
systemTimer
.
createTimer
(
options
);
let
triggerTime
=
new
Date
().
getTime
()
let
triggerTime
=
new
Date
().
getTime
();
triggerTime
+=
3000
triggerTime
+=
3000
;
systemTimer
.
startTimer
(
timerId
,
triggerTime
)
systemTimer
.
startTimer
(
timerId
,
triggerTime
);
systemTimer
.
stopTimer
(
timerId
).
then
((
data
)
=>
{
try
{
console
.
log
(
`Succeeded in stopping timer. Data:`
+
JSON
.
stringify
(
data
));
systemTimer
.
stopTimer
(
timerId
).
then
(()
=>
{
console
.
info
(
`Succeeded in stopping timer.`
);
}).
catch
((
error
)
=>
{
}).
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
}
`
);
}
}
}
}
}
```
```
...
@@ -294,23 +320,28 @@ destroyTimer(timer: number, callback: AsyncCallback<void>): void
...
@@ -294,23 +320,28 @@ destroyTimer(timer: number, callback: AsyncCallback<void>): void
```
js
```
js
export
default
{
export
default
{
async
systemTimer
()
{
async
systemTimer
()
{
let
options
=
{
let
options
=
{
type
:
systemTimer
.
TIMER_TYPE_REALTIME
,
type
:
systemTimer
.
TIMER_TYPE_REALTIME
,
repeat
:
false
repeat
:
false
}
let
timerId
=
await
systemTimer
.
createTimer
(
options
);
let
triggerTime
=
new
Date
().
getTime
();
triggerTime
+=
3000
;
systemTimer
.
startTimer
(
timerId
,
triggerTime
);
systemTimer
.
stopTimer
(
timerId
);
try
{
systemTimer
.
destroyTimer
(
timerId
,
(
error
)
=>
{
if
(
error
)
{
console
.
info
(
`Failed to destroy timer. message:
${
error
.
message
}
, code:
${
error
.
code
}
`
);
return
;
}
}
let
timerId
=
await
systemTimer
.
createTimer
(
options
)
console
.
info
(
`Succeeded in destroying timer.`
);
let
triggerTime
=
new
Date
().
getTime
()
});
triggerTime
+=
3000
}
catch
(
e
)
{
systemTimer
.
startTimer
(
timerId
,
triggerTime
)
console
.
info
(
`Failed to destroying timer. message:
${
e
.
message
}
, code:
${
e
.
code
}
`
);
systemTimer
.
stopTimer
(
timerId
)
systemTimer
.
destroyTimer
(
timerId
,
(
error
)
=>
{
if
(
error
)
{
console
.
error
(
`Failed to destroy timer. Cause:`
+
JSON
.
stringify
(
error
));
return
;
}
});
}
}
}
}
}
```
```
...
@@ -338,21 +369,25 @@ destroyTimer(timer: number): Promise<void>
...
@@ -338,21 +369,25 @@ destroyTimer(timer: number): Promise<void>
```
js
```
js
export
default
{
export
default
{
async
systemTimer
(){
async
systemTimer
(){
let
options
=
{
let
options
=
{
type
:
systemTimer
.
TIMER_TYPE_REALTIME
,
type
:
systemTimer
.
TIMER_TYPE_REALTIME
,
repeat
:
false
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
));
}).
catch
((
error
)
=>
{
console
.
error
(
`Failed to destroy timer. Cause:`
+
JSON
.
stringify
(
error
));
});
}
}
let
timerId
=
await
systemTimer
.
createTimer
(
options
);
let
triggerTime
=
new
Date
().
getTime
();
triggerTime
+=
3000
;
systemTimer
.
startTimer
(
timerId
,
triggerTime
);
systemTimer
.
stopTimer
(
timerId
);
try
{
systemTimer
.
destroyTimer
(
timerId
).
then
(()
=>
{
console
.
info
(
`Succeeded in destroying timer.`
);
}).
catch
((
error
)
=>
{
console
.
info
(
`Failed to destroy timer. message:
${
error
.
message
}
, code:
${
error
.
code
}
`
);
});
}
catch
(
e
)
{
console
.
info
(
`Failed to destroying timer. message:
${
e
.
message
}
, code:
${
e
.
code
}
`
);
}
}
}
}
```
```
\ No newline at end of file
zh-cn/application-dev/reference/errorcodes/errorcode-time.md
0 → 100644
浏览文件 @
8ff6ec1b
# 时间时区服务错误码
## -1 锁屏服务异常
**错误信息**
The parameter check failed or permission denied or system error.
**错误描述**
参数校验失败、权限校验失败或者时间时区服务异常。
**可能原因**
该错误码代表一种通用错误码,可根据错误信息判断具体异常,可能原因如下:
1.
参数校验失败,传入参数无效。
2.
权限校验失败,权限未配置。应用设置时间未配置ohos.permission.SET_TIME或者设置时区未配置ohos.permission.SET_TIME_ZONE。
3.
系统运行异常。内存申请、多线程处理等内核通用错误。
**处理步骤**
1.
参数校验失败,传入参数无效。检查参数是否按照要求传入。
2.
权限校验失败,应用设置时间配置ohos.permission.SET_TIME或者设置时区配置ohos.permission.SET_TIME_ZONE。
3.
系统运行异常。确认内存是否足够。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录