代码拉取完成,页面将自动刷新
同步操作将从 OpenHarmony/time_time_service 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
The timing and time module provides APIs for managing the system time.
Figure 1 Subsystem architecture
/base/time/time_service
├── etc # Process configuration files
├── figures # Architecture diagram
├── framework/js/napi # the js interface resolves to the napi interface
├── interfaces/inner_api # external interface code provided by the component
├── services # time service realization
│ └── sa_profile # module contains the config files of system services and processes
├── test # unit test of interface
└── utils # module contains log printing and constants for ordered commonEvent
Table 1 Major functions of systemTime
Interface name | describe |
---|---|
setTime(time : number) : Promise | Set the system time (1970-01-01 to the present in milliseconds), Promise method. |
setTime(time : number, callback : AsyncCallback) : void | Set the system time (1970-01-01 to the present in milliseconds), callback mode. |
setDate(date: Date, callback: AsyncCallback): void; | Set the system time (Date format), Promise method. |
setDate(date: Date): Promise | Set system time (Date format), callback method. |
setTimezone(timezone: string, callback: AsyncCallback): void | Set the system time zone, callback method. |
setTimezone(timezone: string): Promise | Set the system time zone, Promise method. |
表 2 Major functions of systemTimer
Interface name | describe |
---|---|
createTimer(options: TimerOptions, callback: AsyncCallback): void | Create timer, callback method |
createTimer(options: TimerOptions): Promise | Create timer, promise method |
startTimer(timer: number, triggerTime: number, callback: AsyncCallback): void | Start the timer, callback mode |
startTimer(timer: number, triggerTime: number): Promise | Start the timer, promise mode |
stopTimer(timer: number, callback: AsyncCallback): void | Stop the timer, callback mode |
stopTimer(timer: number): Promise | Stop the timer, promise mode |
destroyTimer(timer: number, callback: AsyncCallback): void | Destroy the timer, callback method |
destroyTimer(timer: number): Promise | Destroy the timer, the promise method |
表 3 parameter TimerOptions description of systemTimer
name | type | illustrate |
---|---|---|
type | number | Timer type. If the value is 1, it is represented as the system startup time timer (the timer start time cannot be later than the currently set system time); If the value is 2, it is indicated as a wake-up timer; When the value is 4, it is represented as a precision timer; If the value is 5, it is represented as an IDLE mode timer (not supported). |
repeat | boolean | true Is a cyclic timer, false is a single timer. |
interval | number | If it is a cyclic timer, the repeat value should be greater than 5000 milliseconds, and the non-repeated timer is set to 0. |
wantAgent | wantAgent | Set the wantagent to notify, and notify when the timer expires. |
callback | => void | Set the callback function, which will be triggered after the timer expires. |
Example fo using systemTime
// Import the module.
import systemTime from '@ohos.systemTime';
// Set the system time asynchronously with a Promise.
var time = 1611081385000;
systemTime.setTime(time).then((value) => {
console.log(`success to systemTime.setTime: ${value}`);
}).catch((err) => {
console.error(`failed to systemTime.setTime because ${err.message}`)
});
// Set the system time asynchronously with a callback.
var time = 1611081385000;
systemTime.setTime(time, (err, value) => {
if (err) {
console.error(`failed to systemTime.setTime because ${err.message}`);
return;
}
console.log(`success to systemTime.setTime: ${value}`);
});
Example fo using systemTimer
// Import the module
import systemTimer from '@ohos.systemTimer';
console.log("start");
var options:TimerOptions{
type:TIMER_TYPE_REALTIME,
repeat:false,
interval:Number.MAX_VALUE/2,
persistent:false
}
console.log("create timer")
let timerId = systemTimer.Timer(options)
console.log("start timer")
let startTimerRes = systemTimer.startTimer(timerId, 100000)
console.log("stop timer")
let stopTimerRes = systemTimer.stopTimer(timerId)
console.log("destroy timer")
let destroyTimerRes = systemTimer.destroyTimer(timerId)
console.log('end');
Time/Timezone subsystem
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。