Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
27ef199a
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看板
未验证
提交
27ef199a
编写于
1月 03, 2023
作者:
O
openharmony_ci
提交者:
Gitee
1月 03, 2023
浏览文件
操作
浏览文件
下载
差异文件
!13058 add time interface
Merge pull request !13058 from wTong888/master
上级
aade4b0d
c67750ed
变更
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
浏览文件 @
27ef199a
此差异已折叠。
点击以展开。
zh-cn/application-dev/reference/apis/js-apis-system-time.md
浏览文件 @
27ef199a
此差异已折叠。
点击以展开。
zh-cn/application-dev/reference/apis/js-apis-system-timer.md
浏览文件 @
27ef199a
...
...
@@ -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
浏览文件 @
27ef199a
# 时间时区子系统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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录